Skip to content

add test case for https://github.com/FasterXML/jackson-core/issues/1397 #4949

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

Merged
merged 4 commits into from
Feb 5, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.StringReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -110,6 +111,79 @@ static DecimalHolder4917 of(BigDecimal value) {
}
}

static class Point {
private Double x;
private Double y;

public Double getX() {
return x;
}

public void setX(Double x) {
this.x = x;
}

public Double getY() {
return y;
}

public void setY(Double y) {
this.y = y;
}
}

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "type",
visible = true)
@JsonSubTypes(@JsonSubTypes.Type(value = CenterResult.class, name = "center"))
static abstract class Result {
private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}

static class CenterResult extends Result {
private Point center;

private Double radius;

public Double getRadius() {
return radius;
}

public void setRadius(Double radius) {
this.radius = radius;
}

public Point getCenter() {
return center;
}

public void setCenter(Point center) {
this.center = center;
}
}

static class Root {
private Result[] results;

public Result[] getResults() {
return results;
}

public void setResults(Result[] results) {
this.results = results;
}
}

/*
/**********************************************************************
/* Helper classes, serializers/deserializers/resolvers
Expand Down Expand Up @@ -470,4 +544,22 @@ public void bigDecimal4917V3() throws Exception
assertEquals(new BigDecimal("100.00"), issue.decimal);
assertEquals(50, issue.number);
}

// https://github.com/FasterXML/jackson-core/issues/1397
@Test
public void issue1397() throws Exception {
final String dataString = a2q("{ 'results': [ { " +
"'radius': 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, " +
"'type': 'center', " +
"'center': { " +
"'x': -11.0, " +
"'y': -2.0 } } ] }");

Root object = MAPPER.readValue(dataString, Root.class);

CenterResult result = (CenterResult) Arrays.stream(object.getResults()).findFirst().get();

assertEquals(-11.0d, result.getCenter().getX());
assertEquals(-2.0d, result.getCenter().getY());
}
}