Closed Raniz85 closed 7 years ago
This works:
public class UuidWrapper {
public static final String SCHEMA = "message StreamId {\n"
+ " required string id = 1;\n"
+ " required double number = 2;\n"
+ "}";
private UUID id;
private Double number;
public UUID getId() {
return id;
}
public void setId(final UUID id) {
this.id = id;
}
public Double getNumber() {
return number;
}
public void setNumber(final Double number) {
this.number = number;
}
public static void main(String[] args) throws IOException {
ProtobufMapper mapper = new ProtobufMapper();
UuidWrapper original = new UuidWrapper();
original.setId(UUID.randomUUID());
original.setNumber(42d);
ProtobufSchema schema = ProtobufSchemaLoader.std.parse(
"message UuidWrapper {\n"
+ " required string id = 1;\n"
+ " required double number = 2;\n"
+ "}"
);
byte[] message = mapper.writer(schema).writeValueAsBytes(original);
UuidWrapper deserialised = mapper.reader(schema).forType(UuidWrapper.class).readValue(message);
System.out.println(Objects.equals(original.getId(), deserialised.getId()));
System.out.println(Objects.equals(original.getNumber(), deserialised.getNumber()));
}
}
true
true
Dup of #68, fixed for master
(2.9.0.pr3).
Sorry that I missed that one. I could swear I searched before opening this issue, but that might have been in the old repo...
@Raniz85 no prob, I just closed it recently so easy to miss. Plus the repo move.
This code:
Produces this exception:
I get the same error if with a
Double
(but it complains aboutNumber
not being a supported root type). Using aString
or adouble
works - butdouble
can't be optional.If I parse the following schema instead:
Then both serialising and deserialising with UUID works.