On Mon, Jun 26, 2017 at 1:08 PM, Michael Liedtke <[email protected]> wrote:
> Hi Tatu,
> The example was using the ClassNameIdResolver as the default resolver (it
> was buried in the linked test case, sorry about the obscurity).
Ah. That makes sense then.
> I took a deeper look at the Jackson-dataformat-ion code and think I found
> the issue. It seems Jackson does provide all the options necessary to make
> this work like you had thought. However, the IonAnnotationTypeSerializer
> didn't implement the "writeTypePrefixForScalar" method so the opportunity to
> write the ion annotation for @JsonValue types was ignored. After adding the
> necessary code to write the ion annotation to this method (copying from
> "writeTypePrefixForObject" method), it works as expected and the annotation
> is written on serialization.
Could you file an issue for `jackson-dataformats-binary` please? Ion
backend just moved there.
(or PR for extra points -- a test case would definitely make sense).
-+ Tatu +-
>
> Michael
>
>
> On Monday, June 26, 2017 at 6:39:34 PM UTC+1, Tatu Saloranta wrote:
>>
>> I haven't quite read the whole thing, but first things first: I think
>> that you should not try to combine `@JsonValue` with polymorphic type
>> handling. This is problematic because of ambiguity (during processing)
>> between type of Java Object being returned by method, and logical type
>> it represents (that is, POJO that has @JsonValue-annotated method).
>> Similar problem affects Delegating `@JsonCreator` approach.
>>
>> Jackson internals will try to handle this case best it can, but as
>> things are I am not 100% confident things work end-to-end.
>> Specific issues relate to TypeSerializer/TypeDeserializer not having
>> proper context to know the distinction (here's the Object for which
>> type id; and here's Object with contents to serialize), as well as
>> possibly differing representations for the two ("shape" in JSON).
>>
>> Having said all of above, code included seems to be missing actual
>> `@JsonTypeInfo` on `ClassA`.
>> Is this intentional? (possible default typing is enabled)
>>
>> -+ Tatu +-
>>
>>
>> On Sun, Jun 25, 2017 at 10:05 AM, Michael Liedtke <[email protected]>
>> wrote:
>> > Hello,
>> > I was hoping for some feedback on the following problem involving Type
>> > Resolvers during serialization of classes that use @JsonValue. The
>> > example I
>> > will give will use the upcoming Ion data-format. Specifically, using Ion
>> > type annotations to resolve types via the
>> > IonAnnotationTypeResolverBuilder
>> > much like the PolymorphicRoundTripTest.
>> >
>> > Given a mapper configured with a module much like in the linked test:
>> >
>> > IonObjectMapper mapper = new IonObjectMapper();
>> > mapper.registerModule(new IonAnnotationModule());
>> >
>> >
>> > And the following classes:
>> >
>> >
>> > @JsonTypeResolver(IonAnnotationTypeResolverBuilder.class)
>> > public static class ClassA {}
>> > public static class SubClassB extends ClassA {
>> > public final String value;
>> > @JsonCreator
>> > public SubClassB(String value) {
>> > this.value = value;
>> > }
>> > @JsonValue
>> > public String getValue() {
>> > return value;
>> > }
>> >
>> >
>> >
>> > @Override
>> >
>> > public String toString() {
>> >
>> > return "SubClassB[value=" + value + "]";
>> >
>> > }
>> >
>> > }
>> >
>> >
>> > I can successfully deserialize to the correct type:
>> >
>> > ClassA a =
>> > mapper.readValue("'some.test.package.SubClassB'::\"some_value\"",
>> > ClassA.class);
>> >
>> > System.out.println(a); //Output: SubClassB[value=some_value]
>> >
>> >
>> > But cannot seem to include type information when serialization:
>> >
>> > System.out.println(mapper.writeValueAsString(a)); //Output: "some_value"
>> >
>> >
>> > The desired output would be:
>> > 'some.test.package.SubClassB'::"some_value". Is
>> > this possible? I see a potential option in the JsonValueSerializer
>> > class
>> > but unsure if/how this would be used to solve the problem.
>> >
>> > Thank you,
>> > Michael
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "jackson-user" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to [email protected].
>> > To post to this group, send email to [email protected].
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.