Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 26, 2025
2 parents c4406ec + 0e9db3d commit eb8c072
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 3 deletions.
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,9 @@ wrongwrong (@k163377)
* Contributed #4749: Fixed problem in StdDelegatingSerializer#serializeWithType where final
serializer lookup was done on the pre-converted value when _delegateSerializer was null
(2.18.1)
* Reported #4878: When serializing a Map via Converter(StdDelegatingSerializer),
a NullPointerException is thrown due to missing key serializer
(2.18.3)

Bernd Ahlers (@bernd)
* Reported #4742: Deserialization with Builder, External type id, `@JsonCreator` failing
Expand Down
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Project: jackson-databind
multiple constructors since 2.18
(reported by Tomáš P)
(fix by Joo-Hyuk K, @cowtowncoder)
#4878: When serializing a Map via Converter(StdDelegatingSerializer),
a NullPointerException is thrown due to missing key serializer
(reported by @wrongwrong)
#4908: Deserialization behavior change with @JsonCreator and
@ConstructorProperties between 2.17 and 2.18
(reported by Gustavo B)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package tools.jackson.databind.convert;

import java.util.Collections;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonFormat;

import tools.jackson.databind.*;
import tools.jackson.databind.module.SimpleModule;
import tools.jackson.databind.module.SimpleSerializers;
import tools.jackson.databind.ser.std.StdDelegatingSerializer;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.util.StdConverter;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MapConversion4878Test extends DatabindTestUtil
{
// [databind#4878]
static class MapWrapper4878 {
final Map<String, Object> value;

MapWrapper4878(Map<String, Object> value) {
this.value = value;
}
}

static class WrapperConverter4878 extends StdConverter<MapWrapper4878, Object> {
@Override
public Object convert(MapWrapper4878 value) {
return value.value;
}
}

@SuppressWarnings("serial")
static class Serializers4878 extends SimpleSerializers {
@Override
public ValueSerializer<?> findSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc, JsonFormat.Value formatOverrides) {
Class<?> rawClass = type.getRawClass();
if (MapWrapper4878.class.isAssignableFrom(rawClass)) {
return new StdDelegatingSerializer(new WrapperConverter4878());
}
return super.findSerializer(config, type, beanDesc, formatOverrides);
}
}

// [databind#4878]
@Test
public void testMapConverter() throws Exception
{
SimpleModule sm = new SimpleModule();
sm.setSerializers(new Serializers4878());
final ObjectMapper mapper = jsonMapperBuilder()
.addModule(sm)
.build();
String json = mapper.writeValueAsString(new MapWrapper4878(Collections.singletonMap("a", 1)));
assertEquals(a2q("{'a':1}"), json);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

public class MapConversionsTest
{
final ObjectMapper MAPPER = newJsonMapper();

enum AB { A, B; }

static class Bean {
public Integer A;
public String B;
}

// [Issue#287]
// [databind#287]

@JsonSerialize(converter=RequestConverter.class)
static class Request {
Expand All @@ -50,6 +48,8 @@ public Map<String,Object> convert(final Request value) {
/**********************************************************
*/

private final ObjectMapper MAPPER = newJsonMapper();

/**
* Test that verifies that we can go between couple of types of Maps...
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void serialize(String value, JsonGenerator jgen, SerializationContext pro
}
}

@SuppressWarnings("serial")
static class PrefixStringDeserializer extends StdScalarDeserializer<String>
{
protected PrefixStringDeserializer() {
Expand Down

0 comments on commit eb8c072

Please sign in to comment.