-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 6.0.2 with changed dependencies
- Loading branch information
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package jodd.json; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class PartialTest { | ||
|
||
public static class MyMappingClass { | ||
public String something; | ||
public String somemore; | ||
} | ||
|
||
@Test | ||
void testMapArray() { | ||
final String json = "{" + | ||
"\"field1\": [" + | ||
"{" + | ||
"\"something\": \"else\"," + | ||
"\"somemore\": \"yesplease\"" + | ||
"}" + | ||
"]," + | ||
"\"field2\": true," + | ||
"\"field3\": 1" + | ||
"}"; | ||
|
||
final Map<String, Object> m = new JsonParser() | ||
.map("values.values", MyMappingClass.class) | ||
.parse(json); | ||
|
||
final List<MyMappingClass> mm = (List<MyMappingClass>) m.get("field1"); | ||
|
||
assertEquals(1, mm.size()); | ||
assertEquals("else", mm.get(0).something); | ||
assertEquals("yesplease", mm.get(0).somemore); | ||
} | ||
|
||
@Test | ||
void testMapArrayAlt() { | ||
final String json = "{" + | ||
"\"field1\": [" + | ||
"{" + | ||
"\"something\": \"else\"," + | ||
"\"somemore\": \"yesplease\"" + | ||
"}" + | ||
"]," + | ||
"\"field2\": true," + | ||
"\"field3\": 1" + | ||
"}"; | ||
|
||
final Map<String, Object> m = new JsonParser() | ||
.map("field1.values", MyMappingClass.class) | ||
.useAltPaths() | ||
.parse(json); | ||
|
||
final List<MyMappingClass> mm = (List<MyMappingClass>) m.get("field1"); | ||
|
||
assertEquals(1, mm.size()); | ||
assertEquals("else", mm.get(0).something); | ||
assertEquals("yesplease", mm.get(0).somemore); | ||
} | ||
|
||
|
||
@Test | ||
void testMap() { | ||
final String json = "{" + | ||
"\"field1\":" + | ||
"{" + | ||
"\"something\": \"else\"," + | ||
"\"somemore\": \"yesplease\"" + | ||
"}}"; | ||
|
||
final Map<String, Object> map = new JsonParser() | ||
.map("values", MyMappingClass.class) | ||
.parse(json); | ||
|
||
final MyMappingClass mm = (MyMappingClass) map.get("field1"); | ||
} | ||
} |