Skip to content

Failed to convert serialized Instant to JSON #405

@jabolina

Description

@jabolina

We can serialize a java.time.Instant through the WrappedMessage, where it writes an int64 and int32:

if (t instanceof Instant instant) {
out.writeInt64(WRAPPED_INSTANT_SECONDS, instant.getEpochSecond());
out.writeInt32(WRAPPED_INSTANT_NANOS, instant.getNano());
out.flush();
return;
}

However, the conversion to JSON fails, resulting in an empty String. I see other (primitive) types work out of the box. A simple reproducer:

   @Test
   public void testInstant() throws Exception {
      ImmutableSerializationContext ctx = createContext();

      byte[] data = ProtobufUtil.toWrappedByteArray(ctx, Instant.EPOCH);
      System.out.println(ProtobufUtil.toCanonicalJSON(ctx, data));
   }

I've run this from the ProtobufUtilTest class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions