Skip to content

Commit

Permalink
add test case for FasterXML/jackson-core#1397
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Feb 4, 2025
1 parent efe5d07 commit 00208a8
Showing 1 changed file with 93 additions and 0 deletions.
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,23 @@ 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 {
var 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().orElseThrow();

System.out.println(result.getCenter().getX());
System.out.println(result.getCenter().getY());
}
}

0 comments on commit 00208a8

Please sign in to comment.