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

Add passing test to close #3277 #4259

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,11 @@ Kevin Baes (BaesKevin@github)
as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY`
(2.16.0)

John Hendrikx (hjohn@github)
* Reported #3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal`
instead of `Double`
(2.16.0)

David Schlosnagle (schlosna@github)
* Contributed #4008: Optimize `ObjectNode` findValue(s) and findParent(s) fast paths
(2.16.0)
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 @@ -29,6 +29,9 @@ Project: jackson-databind
#3133: Map deserialization results in different numeric classes based on
json ordering (BigDecimal / Double) when used in combination with @JsonSubTypes
(reported by @mreiterer)
#3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal`
instead of `Double`
(reported John H)
#3251: Generic class with generic field of runtime type `Double` is deserialized
as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY`
(reported by Kevin B)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.fasterxml.jackson.databind.struct;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.databind.ObjectMapper;

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

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

/**
* Test to verify that [databind#3277] is fixed.
*/
public class UnwrappedDoubleWithAnySetter3277Test
{
static class Holder {
Object value1;

@JsonUnwrapped
Holder2 holder2;

public Object getValue1() {
return value1;
}

public void setValue1(Object value1) {
this.value1 = value1;
}
}

static class Holder2 {
Map<String, Object> data = new HashMap<>();

@JsonAnyGetter
public Map<String, Object> getData() {
return data;
}

@JsonAnySetter
public void setAny(String key, Object value) {
data.put(key, value);
}
}

private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testIsInstanceOfDouble() throws Exception
{
Holder holder = MAPPER.readValue("{\"value1\": -60.0, \"value2\": -60.0}", Holder.class);

// Validate type
assertEquals(Double.class, holder.value1.getClass());
assertEquals(Double.class, holder.holder2.data.get("value2").getClass());
// Validate value
assertEquals(-60.0, holder.value1);
assertEquals(-60.0, holder.holder2.data.get("value2"));
}
}