MCPcopy
hub / github.com/google/gson / serialize

Method serialize

src/main/java/com/google/gson/MapTypeAdapter.java:36–58  ·  view source on GitHub ↗
(Map src, Type typeOfSrc, JsonSerializationContext context)

Source from the content-addressed store, hash-verified

34final class MapTypeAdapter extends BaseMapTypeAdapter {
35
36 public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) {
37 JsonObject map = new JsonObject();
38 Type childGenericType = null;
39 if (typeOfSrc instanceof ParameterizedType) {
40 Class<?> rawTypeOfSrc = $Gson$Types.getRawType(typeOfSrc);
41 childGenericType = $Gson$Types.getMapKeyAndValueTypes(typeOfSrc, rawTypeOfSrc)[1];
42 }
43
44 for (Map.Entry entry : (Set<Map.Entry>) src.entrySet()) {
45 Object value = entry.getValue();
46
47 JsonElement valueElement;
48 if (value == null) {
49 valueElement = JsonNull.createJsonNull();
50 } else {
51 Type childType = (childGenericType == null)
52 ? value.getClass() : childGenericType;
53 valueElement = serialize(context, value, childType);
54 }
55 map.add(String.valueOf(entry.getKey()), valueElement);
56 }
57 return map;
58 }
59
60 public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
61 throws JsonParseException {

Callers

nothing calls this directly

Calls 6

createJsonNullMethod · 0.95
addMethod · 0.95
entrySetMethod · 0.80
getRawTypeMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected