Skip to content

Commit ff1fce1

Browse files
committed
Fixing Json instantiation using reflection
1 parent bc42584 commit ff1fce1

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/main/java/org/andrejs/json/Json.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public int hashCode() {
7373

7474
@SuppressWarnings("unchecked")
7575
public <T> T get(String key) {
76-
return (T) map.get(key);
76+
return (T) toMap().get(key);
7777
}
7878

7979
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -146,8 +146,10 @@ public Json copy() {
146146

147147
/** Read declared field values using reflection **/
148148
Map<String, Object> readFields() {
149-
Map<String, Object> fieldVals = new LinkedHashMap<String, Object>();
149+
Map<String, Object> fieldVals = new LinkedHashMap<>();
150150
for(Field f: getClass().getDeclaredFields()) {
151+
if(f.getName().contains("$"))
152+
continue;
151153
Object val = JsonSerializer.getFieldValue(f, this);
152154
if( val != null && !isStatic(f.getModifiers()) )
153155
fieldVals.put( f.getName() , val);

src/test/java/org/andrejs/json/JsonTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void containsAnonymousClassFields() throws Exception {
4343
String key2 = "val";
4444
};
4545
int val = json.get("key");
46+
System.out.println(json);
4647
assertEquals(123, val);
4748
assertEquals("val", json.get("key2"));
4849
}

0 commit comments

Comments
 (0)