@@ -17,13 +17,13 @@ public class GeneralFieldMappingObjectAdapter<T> extends TypeAdapter<T> {
1717 private Map <String , Type > canonicalFields ;
1818 private FieldNamingPolicy fieldNamingPolicy ;
1919
20- public GeneralFieldMappingObjectAdapter (Class clazz , Map <String , Type > fields , FieldNamingPolicy policy ) {
20+ public GeneralFieldMappingObjectAdapter (Class clazz , Map <String , Type > jsonFields , FieldNamingPolicy policy ) {
2121 this .targetClazz = clazz ;
22- this .displayFields = fields ;
22+ this .displayFields = jsonFields ;
2323 this .fieldNamingPolicy = policy ;
2424 this .canonicalFields = new HashMap <>();
25- if (null != fields ) {
26- for (Map .Entry <String , Type > entry : fields .entrySet ()) {
25+ if (null != jsonFields ) {
26+ for (Map .Entry <String , Type > entry : jsonFields .entrySet ()) {
2727 String displayName = entry .getKey ();
2828 String identifyName = toCanonicalName (displayName , policy );
2929 this .canonicalFields .put (identifyName , entry .getValue ());
@@ -64,7 +64,7 @@ public void write(JsonWriter jsonWriter, T t) throws IOException {
6464 jsonWriter .name (outputName ).value (value );
6565 }
6666 } catch (Exception ex ) {
67- ;
67+ ex . printStackTrace () ;
6868 }
6969 }
7070 jsonWriter .endObject ();
@@ -111,35 +111,6 @@ public T read(JsonReader jsonReader) throws IOException {
111111 ex .printStackTrace ();
112112 }
113113 }
114- // for (Map.Entry<String, Type> entry: this.displayFields.entrySet()) {
115- // String fieldName = entry.getKey();
116- // Type valueType = entry.getValue();
117- // JsonElement value = jsonObject.get(fieldName);
118- // String identifyFieldName = toCanonicalName(fieldName, this.fieldNamingPolicy);
119- // try {
120- // Field field = result.getClass().getDeclaredField(identifyFieldName);
121- // field.setAccessible(true);
122- // if (valueType.equals(String.class)) {
123- // field.set(result, value.getAsString());
124- // } else if (valueType.equals(Integer.class)) {
125- // field.set(result, value.getAsInt());
126- // } else if (valueType.equals(Boolean.class)) {
127- // field.set(result, value.getAsBoolean());
128- // } else if (valueType.equals(Character.class)) {
129- // field.set(result, value.getAsByte());
130- // } else if (valueType.equals(Long.class)) {
131- // field.set(result, value.getAsLong());
132- // } else if (valueType.equals(Float.class)) {
133- // field.set(result, value.getAsFloat());
134- // } else if (valueType.equals(Double.class)) {
135- // field.set(result, value.getAsDouble());
136- // } else {
137- // field.set(result, value);
138- // }
139- // } catch (Exception ex) {
140- // ex.printStackTrace();
141- // }
142- // }
143114 jsonReader .endObject ();
144115 return result ;
145116 } catch (InstantiationException e ) {
0 commit comments