Examples of MyDto


Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenJsonArray_whenDeserializingAsArray_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
        final ObjectMapper mapper = new ObjectMapper();

        final List<MyDto> listOfDtos = Lists.newArrayList(new MyDto("a", 1, true), new MyDto("bc", 3, false));
        final String jsonArray = mapper.writeValueAsString(listOfDtos);
        // [{"stringValue":"a","intValue":1,"booleanValue":true},{"stringValue":"bc","intValue":3,"booleanValue":false}]

        final MyDto[] asArray = mapper.readValue(jsonArray, MyDto[].class);
        assertThat(asArray[0], instanceOf(MyDto.class));
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenJsonArray_whenDeserializingAsListWithNoTypeInfo_thenNotCorrect() throws JsonParseException, JsonMappingException, IOException {
        final ObjectMapper mapper = new ObjectMapper();

        final List<MyDto> listOfDtos = Lists.newArrayList(new MyDto("a", 1, true), new MyDto("bc", 3, false));
        final String jsonArray = mapper.writeValueAsString(listOfDtos);
        // [{"stringValue":"a","intValue":1,"booleanValue":true},{"stringValue":"bc","intValue":3,"booleanValue":false}]

        final List<MyDto> asList = mapper.readValue(jsonArray, List.class);
        assertThat((Object) asList.get(0), instanceOf(LinkedHashMap.class));
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenJsonArray_whenDeserializingAsListWithTypeReferenceHelp_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
        final ObjectMapper mapper = new ObjectMapper();

        final List<MyDto> listOfDtos = Lists.newArrayList(new MyDto("a", 1, true), new MyDto("bc", 3, false));
        final String jsonArray = mapper.writeValueAsString(listOfDtos);
        // [{"stringValue":"a","intValue":1,"booleanValue":true},{"stringValue":"bc","intValue":3,"booleanValue":false}]

        final List<MyDto> asList = mapper.readValue(jsonArray, new TypeReference<List<MyDto>>() {
        });
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenJsonArray_whenDeserializingAsListWithJavaTypeHelp_thenCorrect() throws JsonParseException, JsonMappingException, IOException {
        final ObjectMapper mapper = new ObjectMapper();

        final List<MyDto> listOfDtos = Lists.newArrayList(new MyDto("a", 1, true), new MyDto("bc", 3, false));
        final String jsonArray = mapper.writeValueAsString(listOfDtos);
        // [{"stringValue":"a","intValue":1,"booleanValue":true},{"stringValue":"bc","intValue":3,"booleanValue":false}]

        final CollectionType javaType = mapper.getTypeFactory().constructCollectionType(List.class, MyDto.class);
        final List<MyDto> asList = mapper.readValue(jsonArray, javaType);
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenFieldTypeIsIgnored_whenDtoIsSerialized_thenCorrect() throws JsonParseException, IOException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.addMixInAnnotations(String.class, MyMixInForString.class);
        final MyDto dtoObject = new MyDto();
        dtoObject.setBooleanValue(true);

        final String dtoAsString = mapper.writeValueAsString(dtoObject);

        assertThat(dtoAsString, containsString("intValue"));
        assertThat(dtoAsString, containsString("booleanValue"));
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenIgnoringNullFieldsGlobally_whenWritingObjectWithNullField_thenIgnored() throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL);
        final MyDto dtoObject = new MyDto();

        final String dtoAsString = mapper.writeValueAsString(dtoObject);

        assertThat(dtoAsString, containsString("intValue"));
        assertThat(dtoAsString, containsString("booleanValue"));
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenIgnoringMapNullValue_whenWritingMapObjectWithNullValue_thenIgnored() throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

        final MyDto dtoObject1 = new MyDto();

        final Map<String, MyDto> dtoMap = new HashMap<String, MyDto>();
        dtoMap.put("dtoObject1", dtoObject1);
        dtoMap.put("dtoObject2", null);
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenIgnoringMapValueObjectWithNullField_whenWritingMapValueObjectWithNullField_thenIgnored() throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(Include.NON_NULL);

        final MyDto dtoObject = new MyDto();

        final Map<String, MyDto> dtoMap = new HashMap<String, MyDto>();
        dtoMap.put("dtoObject", dtoObject);

        final String dtoMapAsString = mapper.writeValueAsString(dtoMap);
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenAllowingMapObjectWithNullKey_whenWritingMapObjectWithNullKey_thenAllowed() throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializerProvider().setNullKeySerializer(new MyDtoNullKeySerializer());

        final MyDto dtoObject = new MyDto();
        dtoObject.setStringValue("dtoObjectString");

        final Map<String, MyDto> dtoMap = new HashMap<String, MyDto>();
        dtoMap.put(null, dtoObject);

        final String dtoMapAsString = mapper.writeValueAsString(dtoMap);
View Full Code Here

Examples of org.baeldung.jackson.dtos.MyDto

    @Test
    public final void givenAllowingMapObjectOneNullKey_whenWritingMapObjectWithTwoNullKeys_thenOverride() throws JsonProcessingException {
        final ObjectMapper mapper = new ObjectMapper();
        mapper.getSerializerProvider().setNullKeySerializer(new MyDtoNullKeySerializer());

        final MyDto dtoObject1 = new MyDto();
        dtoObject1.setStringValue("dtoObject1String");

        final MyDto dtoObject2 = new MyDto();
        dtoObject2.setStringValue("dtoObject2String");

        final Map<String, MyDto> dtoMap = new HashMap<String, MyDto>();
        dtoMap.put(null, dtoObject1);
        dtoMap.put(null, dtoObject2);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.