Skip to content

Commit

Permalink
Fixes #251: fix buffering of Ion Timestamp values
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 1, 2024
1 parent 3753cd7 commit 3285388
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ protected TimestampSerializer() {
}

@Override
public void serialize(Timestamp value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
IonGenerator joiGenerator = (IonGenerator) jgen;
joiGenerator.writeValue(value);
public void serialize(Timestamp value, JsonGenerator g, SerializerProvider provider) throws IOException {
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 com.fasterxml.jackson.dataformat.ion.failing;
package com.fasterxml.jackson.dataformat.ion;

import org.junit.Test;

import com.amazon.ion.Timestamp;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -15,12 +16,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 @@ -38,10 +57,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 3285388

Please sign in to comment.