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 · May be fixed by #411
Open

Failed to convert serialized Instant to JSON #405

jabolina opened this issue Jan 16, 2025 · 0 comments · May be fixed by #411

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.

jabolina added a commit to jabolina/protostream that referenced this issue Jan 27, 2025
* Instant and Date objects not handled during JSON conversion.
* Additionally, these objects try to convert as primitive types. This
  loses all the type context for the conversion back from JSON.
* Require adapters from the types module to perform the conversion to
  JSON.
jabolina added a commit to jabolina/protostream that referenced this issue Jan 27, 2025
* Instant and Date objects not handled during JSON conversion.
* Additionally, these objects try to convert as primitive types. This
  loses all the type context for the conversion back from JSON.
* Require adapters from the types module to perform the conversion to
  JSON.
@jabolina jabolina linked a pull request Jan 27, 2025 that will close this issue
jabolina added a commit to jabolina/protostream that referenced this issue Feb 14, 2025
* Instant and Date objects not handled during JSON conversion.
* Additionally, these objects try to convert as primitive types. This
  loses all the type context for the conversion back from JSON.
* Require adapters from the types module to perform the conversion to
  JSON.
* Updates JSON serialization to support nested types in lists and
  wrapped messages.
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

Successfully merging a pull request may close this issue.

1 participant