kryo icon indicating copy to clipboard operation
kryo copied to clipboard

Can BigDecimalSerializer support round_up or round_down features?

Open jackjoesh opened this issue 3 years ago • 5 comments

Can BigDecimalSerializer support round_up or round_down features? Or is there any spi that can extend this kind of features? Thank you

jackjoesh avatar Apr 21 '22 18:04 jackjoesh

What do you mean by that? Can you give me an example of what you want Kryo to do?

theigl avatar Apr 22 '22 15:04 theigl

What do you mean by that? Can you give me an example of what you want Kryo to do?

@BigDecimalCut(accuracy=8, roundHalfUp=true)
private BigDecimal value;

Attributes can be annotated to control the number of digits after the decimal point and whether to round or not

jackjoesh avatar Apr 24 '22 02:04 jackjoesh

What do you mean by that? Can you give me an example of what you want Kryo to do?

Sorry, I changed the question, can I get the custom annotation on the field in my custom serializer? I hope some properties in these annotations will affect the serialization rules. At present, I found that only annotation properties can be obtained in CachedFields, not in custom serializers.

jackjoesh avatar Apr 25 '22 06:04 jackjoesh

can I get the custom annotation on the field in my custom serializer? I hope some properties in these annotations will affect the serialization rules.

Unfortunately, this isn't possible at the moment. We would need to extend the Serializer interface with overloaded methods like this:

public abstract void write (Kryo kryo, Output output, T object, CachedField field);

public abstract T read (Kryo kryo, Input input, Class<? extends T> type, CachedField field);

Or provide some type of SerializerContext object to the methods.

This would require some major changes, but could probably be solved in a backwards-compatible way by making the new methods default methods that simply delegate to the existing methods without the additional context parameter.

If you want, you can provide a PR for this for further discussion.

theigl avatar Apr 27 '22 08:04 theigl

can I get the custom annotation on the field in my custom serializer? I hope some properties in these annotations will affect the serialization rules.

Unfortunately, this isn't possible at the moment. We would need to extend the Serializer interface with overloaded methods like this:

public abstract void write (Kryo kryo, Output output, T object, CachedField field);

public abstract T read (Kryo kryo, Input input, Class<? extends T> type, CachedField field);

Or provide some type of SerializerContext object to the methods.

This would require some major changes, but could probably be solved in a backwards-compatible way by making the new methods default methods that simply delegate to the existing methods without the additional context parameter.

If you want, you can provide a PR for this for further discussion.

thank you, I will try it

jackjoesh avatar May 06 '22 18:05 jackjoesh