Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return new Object() as default value for "empty" for java.lang.Object #3490

Open
wants to merge 1 commit into
base: 2.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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