Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 1, 2024
2 parents 5f8e2a4 + 39992d5 commit f9c7181
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ protected TimestampSerializer() {
}

@Override
public void serialize(Timestamp value, JsonGenerator jgen, SerializerProvider provider)
{
IonGenerator joiGenerator = (IonGenerator) jgen;
joiGenerator.writeValue(value);
public void serialize(Timestamp value, JsonGenerator g, SerializerProvider provider) {
if (g instanceof IonGenerator) {
((IonGenerator) g).writeValue(value);
} else {
// Otherwise probably `TokenBuffer`, so
g.writeEmbeddedObject(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package tools.jackson.dataformat.ion.failing;
package tools.jackson.dataformat.ion;

import org.junit.Test;

import com.amazon.ion.Timestamp;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand All @@ -17,12 +18,30 @@
// For [dataformats-binary#251]
public class IonTimestampDeser251Test
{
static class Message {
static class MessageWithoutTimestamp {
final String message;
final Integer count;

@JsonCreator
public Message(@JsonProperty("message") String message,
public MessageWithoutTimestamp(@JsonProperty("message") String message,
@JsonProperty("count") Integer count) {
this.message = message;
this.count = count;
}

public String getMessage() {
return message;
}
}

static class MessageWithTimestamp {
final String message;
final Integer count;

public Timestamp timestamp;

@JsonCreator
public MessageWithTimestamp(@JsonProperty("message") String message,
@JsonProperty("count") Integer count) {
this.message = message;
this.count = count;
Expand All @@ -40,10 +59,21 @@ public String getMessage() {

// [dataformats-binary#251]
@Test
public void testTimestampDeserWithBuffering() throws Exception {
public void testDeserWithIgnoredBufferedTimestamp() throws Exception {
String ion = "{message: \"Hello, world\", timestamp:2021-03-10T01:49:30.242-00:00}";
MessageWithoutTimestamp message = ION_MAPPER.readValue(ion,
MessageWithoutTimestamp.class);
assertNotNull(message);
assertEquals("Hello, world", message.message);
}

@Test
public void testDeserWithBufferedTimestamp() throws Exception {
String ion = "{message: \"Hello, world\", timestamp:2021-03-10T01:49:30.242-00:00}";
Message message = ION_MAPPER.readValue(ion, Message.class);
MessageWithTimestamp message = ION_MAPPER.readValue(ion,
MessageWithTimestamp.class);
assertNotNull(message);
assertEquals("Hello, world", message.message);
assertNotNull(message.timestamp);
}
}
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Active maintainers:

2.17.0 (not yet released)

#251 (ion) Unable to deserialize Object with unknown `Timestamp` field
(reported by @mgoertzen)
#316 (cbor) Uncaught exception in
`com.fasterxml.jackson.dataformat.cbor.CBORParser._finishShortText`
#392: (cbor, smile) Support `StreamReadConstraints.maxDocumentLength`
Expand Down

0 comments on commit f9c7181

Please sign in to comment.