Skip to content
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

Failed to convert serialized Instant to JSON #405

Open
jabolina opened this issue Jan 16, 2025 · 0 comments
Open

Failed to convert serialized Instant to JSON #405

jabolina opened this issue Jan 16, 2025 · 0 comments

Comments

@jabolina
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant