-
-
Notifications
You must be signed in to change notification settings - Fork 180
Issue 368: serialize Sequence as Iterable #369
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
Issue 368: serialize Sequence as Iterable #369
Conversation
…nto jpalacios/issue-368-serialize-sequences-lazily
@juan-palacios Will review soon—would you fill out the CLA and email a scan/photo of the result to info at fasterxml dot com? https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. If you're feeling interested, you could try to do this against the 2.12 branch. The findTypedValueSerializer()
requires a BeanProperty
argument, so I'm not sure whether it would be a simple chang.
Couple of notes: first, use of First of all, lookup should occur earlier than from
Second problem is use of To find out issues it may be necessary to add tests that exercise values like POGOs, and especially polymorphic values. |
I think this could use more work in light of @cowtowncoder's comments |
I've been on leave but I intend to look into @cowtowncoder 's comments |
@juan-palacios Any update? |
Due to item copies and specialized sequences we use, we overrode the default serializer using the followin serialize method: override fun serialize(value: Sequence<*>, gen: JsonGenerator, provider: SerializerProvider) {
gen.writeStartArray()
value.forEach {
provider.defaultSerializeValue(it, gen)
}
gen.writeEndArray()
} We tested this by replacing that with the following...note that we had to add a null for the override fun serialize(value: Sequence<*>, gen: JsonGenerator, provider: SerializerProvider) {
provider.findTypedValueSerializer(
Iterable::class.java,
true,
null
).serialize(
value.asIterable(),
gen,
provider
)
} We are looking forward to seeing better Sequence handling in Kotlin Jackson Module. We do see the benefit of using the iterable serializer to get the handling of unwrapped single values, etc. Is there any way others like us can support getting this into a release beyond the testing I described? |
I noticed I had implemented a similar idea in #675. |
Translating the
Sequence
into anIterable
and using theIterableSerializer
. This will:WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED
Sequence
and serialize them one by oneAs explained on Issue 368, if
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED
is enabled the first value of theSequence
will be retrieve twice, which means theSequence
will have to produce the first element twice.