Skip to content

Instantly share code, notes, and snippets.

@leonardocregis
Last active October 14, 2019 12:51
Show Gist options
  • Select an option

  • Save leonardocregis/4d973a20caec78c3f3ee9a46fbd781c4 to your computer and use it in GitHub Desktop.

Select an option

Save leonardocregis/4d973a20caec78c3f3ee9a46fbd781c4 to your computer and use it in GitHub Desktop.

Revisions

  1. leonardocregis revised this gist Oct 14, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion java - jackson - reading json
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ import org.junit.Test;

    import static org.junit.Assert.assertNotNull;

    public class TT080DgiiOrderResponseTest {
    public class ResponseTest {

    @Test
    public void testParseJson() throws IOException {
  2. leonardocregis created this gist Sep 5, 2019.
    32 changes: 32 additions & 0 deletions java - jackson - reading json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    import com.fasterxml.jackson.databind.ObjectMapper;
    import java.io.IOException;

    import org.junit.Test;

    import static org.junit.Assert.assertNotNull;

    public class TT080DgiiOrderResponseTest {

    @Test
    public void testParseJson() throws IOException {
    String jsonData = "{\n" +
    " \"total\": 100," +
    " \"val\": 2000," +
    "}";

    ObjectMapper objectMapper = new ObjectMapper();
    TT080DgiiOrderResponse response = objectMapper.readValue(jsonData, JsonMapped.class);
    assertNotNull(response);
    }

    }

    .....
    import com.fasterxml.jackson.annotation.JsonProperty;

    public class JsonMapped {
    @JsonProperty("total")
    private Long total
    @JsonProperty("val")
    private Long value;
    }