Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
I've added the empty value to the Object deserializer in maps as `new Object();`.
  • Loading branch information
aivinog1 committed May 18, 2022
1 parent 3be6147 commit d6d421c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
return ctxt.handleUnexpectedToken(Object.class, p);
}

@Override
public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException {
return new Object();
}

@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.fasterxml.jackson.databind.deser.filter;

import java.util.*;

import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidNullException;

import java.util.EnumMap;
import java.util.List;
import java.util.Map;

// For [databind#1402]; configurable null handling, for contents of
// Collections, Maps, arrays
public class NullConversionsForContentTest extends BaseMapTest
Expand Down Expand Up @@ -297,6 +300,15 @@ public void testNullsAsEmptyWithMaps() throws Exception
assertEquals(ABC.A, result.values.entrySet().iterator().next().getKey());
assertEquals("", result.values.entrySet().iterator().next().getValue());
}

// Then: Map<String,Object>
{
NullContentAsEmpty<Map<String,Object>> result
= MAPPER.readValue(MAP_JSON, new TypeReference<NullContentAsEmpty<Map<String,Object>>>() { });
assertEquals(1, result.values.size());
assertEquals("A", result.values.entrySet().iterator().next().getKey());
assertNotNull(result.values.entrySet().iterator().next().getValue());
}
}

/*
Expand Down

0 comments on commit d6d421c

Please sign in to comment.