Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java deserialize json array

@Test
public void givenJsonArrayOfFoos_whenDeserializingToArray_thenCorrect() {
    String json = "[{"intValue":1,"stringValue":"one"}," +
      "{"intValue":2,"stringValue":"two"}]";
    Foo[] targetArray = new GsonBuilder().create().fromJson(json, Foo[].class);

    assertThat(Lists.newArrayList(targetArray), hasItem(new Foo(1, "one")));
    assertThat(Lists.newArrayList(targetArray), hasItem(new Foo(2, "two")));
    assertThat(Lists.newArrayList(targetArray), not(hasItem(new Foo(1, "two"))));
}
Comment

java deserialize json object

@Test
public void whenDeserializingToSimpleObject_thenCorrect() {
    String json = "{"intValue":1,"stringValue":"one"}";

    Foo targetObject = new Gson().fromJson(json, Foo.class);

    assertEquals(targetObject.intValue, 1);
    assertEquals(targetObject.stringValue, "one");
}
Comment

PREVIOUS NEXT
Code Example
Java :: null check in line java 
Java :: Using Looping Construct to Copy Arrays Java 
Java :: java convert 2d array to 1d stream 
Java :: Betrag absolute abs java 
Java :: Java TestNG Data Provider 
Java :: java scanner class time 
Java :: assigning value with for each 
Java :: class c { public static void main(string[] args){ system.out.println("hello"+args[0]);}} output 
Java :: Java Remove Elements 
Java :: kotlin to java converter online 
Java :: java nom de la methode actuel 
Java :: read only jtextfield 
Java :: find maximum number of rides in amusement park python 
Java :: how to know what a valid name for a variable is in java 
Java :: Java Using allOf(Size) 
Java :: which exception is thrown when java is out of memory 
Java :: java string replace last 4 characters 
Java :: lcm 
Java :: leetspeak 
Java :: Changing or Replacing Elements in java map 
Java :: implement hashmap 
Java :: action media scanner scan file android 30 deprecated 
Java :: Java program to demonstrate working of HashTable 
Java :: How to change numbers to english in printf 
Java :: do switch statement always run default java 
Java :: spring code in java 
Java :: HQL . getFirstResult() 
Java :: Caused by: java.lang.IllegalStateException: stream has already been operated upon or closed 
Java :: kano magic wand 
Java :: What are the design patterns involved in JDBC architecture? 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =