Skip to content

Commit

Permalink
Merge branch '2.16' into 2.17
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 7, 2024
2 parents ef34d13 + 83e0bd8 commit f1798b6
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
15 changes: 10 additions & 5 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1730,20 +1730,25 @@ Jan Pachol (janpacho@github)
(2.16.0)

Pieter Dirk Soels (Badbond@github)
* Reprted #4302: Problem deserializing some type of Enums when using
* Reported #4302: Problem deserializing some type of Enums when using
`PropertyNamingStrategy`
(2.16.2)

Stephane Bailliez (sbailliez@github)
* Reported #4409: Deserialization of enums with name defined with different cases
leads to `InvalidDefinitionException`: Multiple fields representing property
(2.16.2)

Muhammad Khalikov (mukham12@github)
* Contributed fix for #4209: Make `BeanDeserializerModifier`/`BeanSerializerModifier`
implement `java.io.Serializable`
(2.17.0)
implement `java.io.Serializable`
(2.17.0)

Eduard Dudar (edudar@github)
* Contributed #4299: Some `Collection` and `Map` fallbacks don't work in GraalVM native image
(2.17.0)
(2.17.0)
Jesper Blomquist (jebl01@github)
* Contributed #4393: Deserialize `java.util.UUID` encoded as Base64 and base64Url with or
without padding
(2.17.0)
(2.17.0)
4 changes: 4 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Project: jackson-databind
#4355: Jackson 2.16 fails attempting to obtain `ObjectWriter` for an `Enum` of which
some value returns null from `toString()`
(reported by @YutaHiguchi-bsn)
#4409: Deserialization of enums with name defined with different cases leads to
`InvalidDefinitionException`: Multiple fields representing property
(reported by Stephane B)
(fix contributed by Joo-Hyuk K)

2.16.1 (24-Dec-2023)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonCreator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
Expand Down Expand Up @@ -1123,6 +1124,10 @@ protected void _renameProperties(Map<String, POJOPropertyBuilder> props)
protected void _renameUsing(Map<String, POJOPropertyBuilder> propMap,
PropertyNamingStrategy naming)
{
// [databind#4409]: Need to skip renaming for Enums, unless Enums are handled as OBJECT format
if (_type.isEnumType() && (_findFormatShape() != JsonFormat.Shape.OBJECT)) {
return;
}
POJOPropertyBuilder[] props = propMap.values().toArray(new POJOPropertyBuilder[propMap.size()]);
propMap.clear();
for (POJOPropertyBuilder prop : props) {
Expand Down Expand Up @@ -1171,6 +1176,29 @@ protected void _renameUsing(Map<String, POJOPropertyBuilder> propMap,
}
}

/**
* Helper method called to check if given property should be renamed using {@link PropertyNamingStrategies}.
*<p>
* NOTE: copied+simplified version of {@code BasicBeanDescription.findExpectedFormat()}.
*
* @since 2.16.2
*/
private JsonFormat.Shape _findFormatShape()
{
JsonFormat.Shape shape = null;
JsonFormat.Value format = _annotationIntrospector.findFormat(_classDef);
if (format != null) {
shape = format.getShape();
}
JsonFormat.Value defFormat = _config.getDefaultPropertyFormat(_classDef.getRawType());
if (defFormat != null) {
if (shape == null) {
shape = defFormat.getShape();
}
}
return shape;
}

protected void _renameWithWrappers(Map<String, POJOPropertyBuilder> props)
{
// 11-Sep-2012, tatu: To support 'MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import java.util.*;
import java.util.stream.Collectors;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.annotation.*;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.cfg.ConfigOverride;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.fasterxml.jackson.databind.deser.enums;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;

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

import static com.fasterxml.jackson.databind.BaseMapTest.jsonMapperBuilder;

// [databind#4409]: PropertyNamingStrategy should not affect to Enums
class EnumWithNamingStrategy4409Test {

enum ColorMode {
RGB,
RGBa,
RGBA
}

static class Bug {
public ColorMode colorMode;
}

@Test
public void testEnumAndPropertyNamingStrategy() throws Exception {
ObjectMapper mapper = jsonMapperBuilder()
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.build();

Bug bug = mapper.readValue("{ \"color_mode\": \"RGBa\"}", Bug.class);

// fails
assertEquals(ColorMode.RGBa, bug.colorMode);
}
}

0 comments on commit f1798b6

Please sign in to comment.