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

Add new methods in Deserializers, Serializers for new IterationType? #3954

Open
cowtowncoder opened this issue May 25, 2023 · 2 comments
Open
Labels
2.16 Issues planned for 2.16

Comments

@cowtowncoder
Copy link
Member

(see #3950 for background)

With 2.16 there's new IterationType which applies to types like Iterator and Stream. Callback interfaces Deserializers and Serializers should probably be extended to have separate callback methods, with default implementation that simply delegates to:

  • Deserializers.findBeanDeserializer()
  • Serializers.findSerializer()
@cowtowncoder cowtowncoder added to-evaluate Issue that has been received but not yet evaluated 2.16 Issues planned for 2.16 and removed to-evaluate Issue that has been received but not yet evaluated labels May 25, 2023
@pjfanning
Copy link
Member

My specific problem is here - https://github.com/FasterXML/jackson-module-scala/blob/b70b62eb1b04b345f6080391fbd3947652dd1fbe/src/main/scala/com/fasterxml/jackson/module/scala/ser/IteratorSerializerModule.scala#L67-L92

With findCollectionLikeSerializer, I am provided with elementTypeSerializer and elementSerializer. With findSerializer, I do not have these. The code seems to work with jackson-module-scala's basic Iterator tests but I'm concerned that I might not have enough coverage - that more complicated wrapped types (ie the type that the Iterator wraps - the T in Iterator<T>) will break because I don't the serializers for that type. Is there a way, I can find the serializers myself?

@cowtowncoder
Copy link
Member Author

cowtowncoder commented May 26, 2023

@pjfanning Good point, it'd be much more convenient to get (de)serializer passed in.

Yes, it is definitely possible to fetch (de)serializer(s) with given JavaType: bit easier for deserializers (since there is no runtime type), and bit more complex for serializers (since you may or may not have type when asked to construct serializer).

A good example of how to do this might be StreamSerializer:

https://github.com/FasterXML/jackson-modules-java8/blob/2.16/datatypes/src/main/java/com/fasterxml/jackson/datatype/jdk8/StreamSerializer.java

and Serializers impl that constructs it:

https://github.com/FasterXML/jackson-modules-java8/blob/2.16/datatypes/src/main/java/com/fasterxml/jackson/datatype/jdk8/Jdk8Serializers.java

although alternatively methods from BasicSerializerFactory or BeanSerializerFactory which call callbacks in Serializers could also work.

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

No branches or pull requests

2 participants