Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-20 Thread Tatu Saloranta
Not 100% sure I understand the question, but if you want to access
information about annotations on property, from your custom
serializer, you need to implement `ContextualSerializer`, and then its
`createContextual()` gets called with `BeanProperty`.
`BeanProperty` has accessors for annotation directly; or, you can then
call `AnnotationIntrospector` (accessible from `SerializerProvider`
that is also passed).

-+ Tatu +-


On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi  wrote:
> Hi All!
>
> But what can I do when I want to use annotation, and I don't have access to
> the mapper?
> Eg:
>
> @JsonSerialize(using = ASerializer.class)
> public class AClass {
> ...
> }
>
> BR, Zsolt
>
> 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a következőt
> írta:
>>
>> Hi,
>>
>> I'm writing a custom serialiizer, extending StdSerializer.
>> In the
>> public void serialize(MoleculeObject mo, JsonGenerator jg,
>> SerializerProvider sp)
>> method I need to be able to access the default json serialization
>> mechanism, but I don't see how to do this.
>> I can't call super.serialize() as its abstract, and using
>> JsonGenerator.writeObject() or SerializerProvider.defaultSerializeValue()
>> end up calling my custom serialize() method and end up with stack overflow.
>>
>> How should I be doing this?
>>
>> Tim
>
> --
> 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 jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-20 Thread Zsolt Balanyi
Hi!

What I meant is that I would like to get (or create ) the default Jackson 
Serializer for the object being serialized, and store as default.
Then I could implement serialize as follows:

@Override
public void serialize(Object o, JsonGenerator jg, SerializerProvider sp) 
throws IOException {
  doMyStuff...
  default.serialize(o, jg, sp);
}

The challenge here is that only a no-arg constructor is called for the 
serializer if the serializer is used in annotation like 
this: @JsonSerialize(using = UIElementSerializer.class)

BR, Zsolt

2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a 
következőt írta:
>
> Not 100% sure I understand the question, but if you want to access 
> information about annotations on property, from your custom 
> serializer, you need to implement `ContextualSerializer`, and then its 
> `createContextual()` gets called with `BeanProperty`. 
> `BeanProperty` has accessors for annotation directly; or, you can then 
> call `AnnotationIntrospector` (accessible from `SerializerProvider` 
> that is also passed). 
>
> -+ Tatu +- 
>
>
> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi  > wrote: 
> > Hi All! 
> > 
> > But what can I do when I want to use annotation, and I don't have access 
> to 
> > the mapper? 
> > Eg: 
> > 
> > @JsonSerialize(using = ASerializer.class) 
> > public class AClass { 
> > ... 
> > } 
> > 
> > BR, Zsolt 
> > 
> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a 
> következőt 
> > írta: 
> >> 
> >> Hi, 
> >> 
> >> I'm writing a custom serialiizer, extending StdSerializer. 
> >> In the 
> >> public void serialize(MoleculeObject mo, JsonGenerator jg, 
> >> SerializerProvider sp) 
> >> method I need to be able to access the default json serialization 
> >> mechanism, but I don't see how to do this. 
> >> I can't call super.serialize() as its abstract, and using 
> >> JsonGenerator.writeObject() or 
> SerializerProvider.defaultSerializeValue() 
> >> end up calling my custom serialize() method and end up with stack 
> overflow. 
> >> 
> >> How should I be doing this? 
> >> 
> >> Tim 
> > 
> > -- 
> > 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 jackson-user...@googlegroups.com . 
> > To post to this group, send email to jackso...@googlegroups.com 
> . 
> > 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-20 Thread Tatu Saloranta
This can not be done from annotation-based serializer: it will
override default logic.
The only way to access what would otherwise be created/used as the
standard serializer is to register `BeanSerializerModifier`, and
override handling of `modifySerializer`.

-+ Tatu +-


On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi  wrote:
> Hi!
>
> What I meant is that I would like to get (or create ) the default Jackson
> Serializer for the object being serialized, and store as default.
> Then I could implement serialize as follows:
>
> @Override
> public void serialize(Object o, JsonGenerator jg, SerializerProvider sp)
> throws IOException {
>   doMyStuff...
>   default.serialize(o, jg, sp);
> }
>
> The challenge here is that only a no-arg constructor is called for the
> serializer if the serializer is used in annotation like this:
> @JsonSerialize(using = UIElementSerializer.class)
>
> BR, Zsolt
>
> 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a
> következőt írta:
>>
>> Not 100% sure I understand the question, but if you want to access
>> information about annotations on property, from your custom
>> serializer, you need to implement `ContextualSerializer`, and then its
>> `createContextual()` gets called with `BeanProperty`.
>> `BeanProperty` has accessors for annotation directly; or, you can then
>> call `AnnotationIntrospector` (accessible from `SerializerProvider`
>> that is also passed).
>>
>> -+ Tatu +-
>>
>>
>> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi 
>> wrote:
>> > Hi All!
>> >
>> > But what can I do when I want to use annotation, and I don't have access
>> > to
>> > the mapper?
>> > Eg:
>> >
>> > @JsonSerialize(using = ASerializer.class)
>> > public class AClass {
>> > ...
>> > }
>> >
>> > BR, Zsolt
>> >
>> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a
>> > következőt
>> > írta:
>> >>
>> >> Hi,
>> >>
>> >> I'm writing a custom serialiizer, extending StdSerializer.
>> >> In the
>> >> public void serialize(MoleculeObject mo, JsonGenerator jg,
>> >> SerializerProvider sp)
>> >> method I need to be able to access the default json serialization
>> >> mechanism, but I don't see how to do this.
>> >> I can't call super.serialize() as its abstract, and using
>> >> JsonGenerator.writeObject() or
>> >> SerializerProvider.defaultSerializeValue()
>> >> end up calling my custom serialize() method and end up with stack
>> >> overflow.
>> >>
>> >> How should I be doing this?
>> >>
>> >> Tim
>> >
>> > --
>> > 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 jackson-user...@googlegroups.com.
>> > To post to this group, send email to jackso...@googlegroups.com.
>> > 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 jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-20 Thread Zsolt Balanyi
Hi!

OK, thanks, then I'll go that way!

BR, Zsolt

2017. március 20., hétfő 20:13:25 UTC+1 időpontban Tatu Saloranta a 
következőt írta:
>
> This can not be done from annotation-based serializer: it will 
> override default logic. 
> The only way to access what would otherwise be created/used as the 
> standard serializer is to register `BeanSerializerModifier`, and 
> override handling of `modifySerializer`. 
>
> -+ Tatu +- 
>
>
> On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi  > wrote: 
> > Hi! 
> > 
> > What I meant is that I would like to get (or create ) the default 
> Jackson 
> > Serializer for the object being serialized, and store as default. 
> > Then I could implement serialize as follows: 
> > 
> > @Override 
> > public void serialize(Object o, JsonGenerator jg, SerializerProvider sp) 
> > throws IOException { 
> >   doMyStuff... 
> >   default.serialize(o, jg, sp); 
> > } 
> > 
> > The challenge here is that only a no-arg constructor is called for the 
> > serializer if the serializer is used in annotation like this: 
> > @JsonSerialize(using = UIElementSerializer.class) 
> > 
> > BR, Zsolt 
> > 
> > 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a 
> > következőt írta: 
> >> 
> >> Not 100% sure I understand the question, but if you want to access 
> >> information about annotations on property, from your custom 
> >> serializer, you need to implement `ContextualSerializer`, and then its 
> >> `createContextual()` gets called with `BeanProperty`. 
> >> `BeanProperty` has accessors for annotation directly; or, you can then 
> >> call `AnnotationIntrospector` (accessible from `SerializerProvider` 
> >> that is also passed). 
> >> 
> >> -+ Tatu +- 
> >> 
> >> 
> >> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi  
> >> wrote: 
> >> > Hi All! 
> >> > 
> >> > But what can I do when I want to use annotation, and I don't have 
> access 
> >> > to 
> >> > the mapper? 
> >> > Eg: 
> >> > 
> >> > @JsonSerialize(using = ASerializer.class) 
> >> > public class AClass { 
> >> > ... 
> >> > } 
> >> > 
> >> > BR, Zsolt 
> >> > 
> >> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a 
> >> > következőt 
> >> > írta: 
> >> >> 
> >> >> Hi, 
> >> >> 
> >> >> I'm writing a custom serialiizer, extending StdSerializer. 
> >> >> In the 
> >> >> public void serialize(MoleculeObject mo, JsonGenerator jg, 
> >> >> SerializerProvider sp) 
> >> >> method I need to be able to access the default json serialization 
> >> >> mechanism, but I don't see how to do this. 
> >> >> I can't call super.serialize() as its abstract, and using 
> >> >> JsonGenerator.writeObject() or 
> >> >> SerializerProvider.defaultSerializeValue() 
> >> >> end up calling my custom serialize() method and end up with stack 
> >> >> overflow. 
> >> >> 
> >> >> How should I be doing this? 
> >> >> 
> >> >> Tim 
> >> > 
> >> > -- 
> >> > 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 jackson-user...@googlegroups.com. 
> >> > To post to this group, send email to jackso...@googlegroups.com. 
> >> > 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 jackson-user...@googlegroups.com . 
> > To post to this group, send email to jackso...@googlegroups.com 
> . 
> > 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-20 Thread Tatu Saloranta
Good luck! That approach is used quite a lot so it should work fine.
Note, too, that it may be combined with ContextualSerializer if you do
need to access annotations.
In fact you can use `createContextual()` sometimes to simply decide if
override is needed at all; if not, return default serializer from that
method and you are good to go (but if so, remember to delegate call).

It would be great to find better ways to allow such "partial"
overrides, in a more convenient way.
But until then, Bean(De)SerializerModifier is the way to go.

-+ Tatu +-


On Mon, Mar 20, 2017 at 1:08 PM, Zsolt Balanyi  wrote:
> Hi!
>
> OK, thanks, then I'll go that way!
>
> BR, Zsolt
>
> 2017. március 20., hétfő 20:13:25 UTC+1 időpontban Tatu Saloranta a
> következőt írta:
>>
>> This can not be done from annotation-based serializer: it will
>> override default logic.
>> The only way to access what would otherwise be created/used as the
>> standard serializer is to register `BeanSerializerModifier`, and
>> override handling of `modifySerializer`.
>>
>> -+ Tatu +-
>>
>>
>> On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi 
>> wrote:
>> > Hi!
>> >
>> > What I meant is that I would like to get (or create ) the default
>> > Jackson
>> > Serializer for the object being serialized, and store as default.
>> > Then I could implement serialize as follows:
>> >
>> > @Override
>> > public void serialize(Object o, JsonGenerator jg, SerializerProvider sp)
>> > throws IOException {
>> >   doMyStuff...
>> >   default.serialize(o, jg, sp);
>> > }
>> >
>> > The challenge here is that only a no-arg constructor is called for the
>> > serializer if the serializer is used in annotation like this:
>> > @JsonSerialize(using = UIElementSerializer.class)
>> >
>> > BR, Zsolt
>> >
>> > 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a
>> > következőt írta:
>> >>
>> >> Not 100% sure I understand the question, but if you want to access
>> >> information about annotations on property, from your custom
>> >> serializer, you need to implement `ContextualSerializer`, and then its
>> >> `createContextual()` gets called with `BeanProperty`.
>> >> `BeanProperty` has accessors for annotation directly; or, you can then
>> >> call `AnnotationIntrospector` (accessible from `SerializerProvider`
>> >> that is also passed).
>> >>
>> >> -+ Tatu +-
>> >>
>> >>
>> >> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi 
>> >> wrote:
>> >> > Hi All!
>> >> >
>> >> > But what can I do when I want to use annotation, and I don't have
>> >> > access
>> >> > to
>> >> > the mapper?
>> >> > Eg:
>> >> >
>> >> > @JsonSerialize(using = ASerializer.class)
>> >> > public class AClass {
>> >> > ...
>> >> > }
>> >> >
>> >> > BR, Zsolt
>> >> >
>> >> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a
>> >> > következőt
>> >> > írta:
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I'm writing a custom serialiizer, extending StdSerializer.
>> >> >> In the
>> >> >> public void serialize(MoleculeObject mo, JsonGenerator jg,
>> >> >> SerializerProvider sp)
>> >> >> method I need to be able to access the default json serialization
>> >> >> mechanism, but I don't see how to do this.
>> >> >> I can't call super.serialize() as its abstract, and using
>> >> >> JsonGenerator.writeObject() or
>> >> >> SerializerProvider.defaultSerializeValue()
>> >> >> end up calling my custom serialize() method and end up with stack
>> >> >> overflow.
>> >> >>
>> >> >> How should I be doing this?
>> >> >>
>> >> >> Tim
>> >> >
>> >> > --
>> >> > 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 jackson-user...@googlegroups.com.
>> >> > To post to this group, send email to jackso...@googlegroups.com.
>> >> > 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 jackson-user...@googlegroups.com.
>> > To post to this group, send email to jackso...@googlegroups.com.
>> > 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 jackson-user+unsubscr...@googlegroups.com.
> To post to this group, send email to jackson-user@googlegroups.com.
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https:

Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-21 Thread Zsolt Balanyi
Hi!

This is exactly what I was wondering... if there is a way to automate the 
default serializer injection, when the custom serializer gets detected.
I am also willing to contribute to the code, if I am provided some guidance.

BR, Zsolt

2017. március 20., hétfő 21:24:27 UTC+1 időpontban Tatu Saloranta a 
következőt írta:
>
> Good luck! That approach is used quite a lot so it should work fine. 
> Note, too, that it may be combined with ContextualSerializer if you do 
> need to access annotations. 
> In fact you can use `createContextual()` sometimes to simply decide if 
> override is needed at all; if not, return default serializer from that 
> method and you are good to go (but if so, remember to delegate call). 
>
> It would be great to find better ways to allow such "partial" 
> overrides, in a more convenient way. 
> But until then, Bean(De)SerializerModifier is the way to go. 
>
> -+ Tatu +- 
>
>
> On Mon, Mar 20, 2017 at 1:08 PM, Zsolt Balanyi  > wrote: 
> > Hi! 
> > 
> > OK, thanks, then I'll go that way! 
> > 
> > BR, Zsolt 
> > 
> > 2017. március 20., hétfő 20:13:25 UTC+1 időpontban Tatu Saloranta a 
> > következőt írta: 
> >> 
> >> This can not be done from annotation-based serializer: it will 
> >> override default logic. 
> >> The only way to access what would otherwise be created/used as the 
> >> standard serializer is to register `BeanSerializerModifier`, and 
> >> override handling of `modifySerializer`. 
> >> 
> >> -+ Tatu +- 
> >> 
> >> 
> >> On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi  
> >> wrote: 
> >> > Hi! 
> >> > 
> >> > What I meant is that I would like to get (or create ) the default 
> >> > Jackson 
> >> > Serializer for the object being serialized, and store as default. 
> >> > Then I could implement serialize as follows: 
> >> > 
> >> > @Override 
> >> > public void serialize(Object o, JsonGenerator jg, SerializerProvider 
> sp) 
> >> > throws IOException { 
> >> >   doMyStuff... 
> >> >   default.serialize(o, jg, sp); 
> >> > } 
> >> > 
> >> > The challenge here is that only a no-arg constructor is called for 
> the 
> >> > serializer if the serializer is used in annotation like this: 
> >> > @JsonSerialize(using = UIElementSerializer.class) 
> >> > 
> >> > BR, Zsolt 
> >> > 
> >> > 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a 
> >> > következőt írta: 
> >> >> 
> >> >> Not 100% sure I understand the question, but if you want to access 
> >> >> information about annotations on property, from your custom 
> >> >> serializer, you need to implement `ContextualSerializer`, and then 
> its 
> >> >> `createContextual()` gets called with `BeanProperty`. 
> >> >> `BeanProperty` has accessors for annotation directly; or, you can 
> then 
> >> >> call `AnnotationIntrospector` (accessible from `SerializerProvider` 
> >> >> that is also passed). 
> >> >> 
> >> >> -+ Tatu +- 
> >> >> 
> >> >> 
> >> >> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi  
>
> >> >> wrote: 
> >> >> > Hi All! 
> >> >> > 
> >> >> > But what can I do when I want to use annotation, and I don't have 
> >> >> > access 
> >> >> > to 
> >> >> > the mapper? 
> >> >> > Eg: 
> >> >> > 
> >> >> > @JsonSerialize(using = ASerializer.class) 
> >> >> > public class AClass { 
> >> >> > ... 
> >> >> > } 
> >> >> > 
> >> >> > BR, Zsolt 
> >> >> > 
> >> >> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a 
> >> >> > következőt 
> >> >> > írta: 
> >> >> >> 
> >> >> >> Hi, 
> >> >> >> 
> >> >> >> I'm writing a custom serialiizer, extending StdSerializer. 
> >> >> >> In the 
> >> >> >> public void serialize(MoleculeObject mo, JsonGenerator jg, 
> >> >> >> SerializerProvider sp) 
> >> >> >> method I need to be able to access the default json serialization 
> >> >> >> mechanism, but I don't see how to do this. 
> >> >> >> I can't call super.serialize() as its abstract, and using 
> >> >> >> JsonGenerator.writeObject() or 
> >> >> >> SerializerProvider.defaultSerializeValue() 
> >> >> >> end up calling my custom serialize() method and end up with stack 
> >> >> >> overflow. 
> >> >> >> 
> >> >> >> How should I be doing this? 
> >> >> >> 
> >> >> >> Tim 
> >> >> > 
> >> >> > -- 
> >> >> > 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 jackson-user...@googlegroups.com. 
> >> >> > To post to this group, send email to jackso...@googlegroups.com. 
> >> >> > 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 jackson-user...@googlegroups.com. 
> >> > To post to this group, send email to jackso...@googlegroups.com. 
> >> > For more options, visit https://g

Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-21 Thread Zsolt Balanyi
This article points out exactly the fact, that the usage of 
BeanSerializerModifier makes in unnecessary to use the annotation!
So I would happily contribute to make the @JsonSerialize smarter. :)

BR, Zsolt

2017. március 21., kedd 8:25:51 UTC+1 időpontban Zsolt Balanyi a következőt 
írta:
>
> Hi!
>
> This is exactly what I was wondering... if there is a way to automate the 
> default serializer injection, when the custom serializer gets detected.
> I am also willing to contribute to the code, if I am provided some 
> guidance.
>
> BR, Zsolt
>
> 2017. március 20., hétfő 21:24:27 UTC+1 időpontban Tatu Saloranta a 
> következőt írta:
>>
>> Good luck! That approach is used quite a lot so it should work fine. 
>> Note, too, that it may be combined with ContextualSerializer if you do 
>> need to access annotations. 
>> In fact you can use `createContextual()` sometimes to simply decide if 
>> override is needed at all; if not, return default serializer from that 
>> method and you are good to go (but if so, remember to delegate call). 
>>
>> It would be great to find better ways to allow such "partial" 
>> overrides, in a more convenient way. 
>> But until then, Bean(De)SerializerModifier is the way to go. 
>>
>> -+ Tatu +- 
>>
>>
>> On Mon, Mar 20, 2017 at 1:08 PM, Zsolt Balanyi  
>> wrote: 
>> > Hi! 
>> > 
>> > OK, thanks, then I'll go that way! 
>> > 
>> > BR, Zsolt 
>> > 
>> > 2017. március 20., hétfő 20:13:25 UTC+1 időpontban Tatu Saloranta a 
>> > következőt írta: 
>> >> 
>> >> This can not be done from annotation-based serializer: it will 
>> >> override default logic. 
>> >> The only way to access what would otherwise be created/used as the 
>> >> standard serializer is to register `BeanSerializerModifier`, and 
>> >> override handling of `modifySerializer`. 
>> >> 
>> >> -+ Tatu +- 
>> >> 
>> >> 
>> >> On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi  
>> >> wrote: 
>> >> > Hi! 
>> >> > 
>> >> > What I meant is that I would like to get (or create ) the default 
>> >> > Jackson 
>> >> > Serializer for the object being serialized, and store as default. 
>> >> > Then I could implement serialize as follows: 
>> >> > 
>> >> > @Override 
>> >> > public void serialize(Object o, JsonGenerator jg, SerializerProvider 
>> sp) 
>> >> > throws IOException { 
>> >> >   doMyStuff... 
>> >> >   default.serialize(o, jg, sp); 
>> >> > } 
>> >> > 
>> >> > The challenge here is that only a no-arg constructor is called for 
>> the 
>> >> > serializer if the serializer is used in annotation like this: 
>> >> > @JsonSerialize(using = UIElementSerializer.class) 
>> >> > 
>> >> > BR, Zsolt 
>> >> > 
>> >> > 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a 
>> >> > következőt írta: 
>> >> >> 
>> >> >> Not 100% sure I understand the question, but if you want to access 
>> >> >> information about annotations on property, from your custom 
>> >> >> serializer, you need to implement `ContextualSerializer`, and then 
>> its 
>> >> >> `createContextual()` gets called with `BeanProperty`. 
>> >> >> `BeanProperty` has accessors for annotation directly; or, you can 
>> then 
>> >> >> call `AnnotationIntrospector` (accessible from `SerializerProvider` 
>> >> >> that is also passed). 
>> >> >> 
>> >> >> -+ Tatu +- 
>> >> >> 
>> >> >> 
>> >> >> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi  
>>
>> >> >> wrote: 
>> >> >> > Hi All! 
>> >> >> > 
>> >> >> > But what can I do when I want to use annotation, and I don't have 
>> >> >> > access 
>> >> >> > to 
>> >> >> > the mapper? 
>> >> >> > Eg: 
>> >> >> > 
>> >> >> > @JsonSerialize(using = ASerializer.class) 
>> >> >> > public class AClass { 
>> >> >> > ... 
>> >> >> > } 
>> >> >> > 
>> >> >> > BR, Zsolt 
>> >> >> > 
>> >> >> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a 
>> >> >> > következőt 
>> >> >> > írta: 
>> >> >> >> 
>> >> >> >> Hi, 
>> >> >> >> 
>> >> >> >> I'm writing a custom serialiizer, extending StdSerializer. 
>> >> >> >> In the 
>> >> >> >> public void serialize(MoleculeObject mo, JsonGenerator jg, 
>> >> >> >> SerializerProvider sp) 
>> >> >> >> method I need to be able to access the default json 
>> serialization 
>> >> >> >> mechanism, but I don't see how to do this. 
>> >> >> >> I can't call super.serialize() as its abstract, and using 
>> >> >> >> JsonGenerator.writeObject() or 
>> >> >> >> SerializerProvider.defaultSerializeValue() 
>> >> >> >> end up calling my custom serialize() method and end up with 
>> stack 
>> >> >> >> overflow. 
>> >> >> >> 
>> >> >> >> How should I be doing this? 
>> >> >> >> 
>> >> >> >> Tim 
>> >> >> > 
>> >> >> > -- 
>> >> >> > 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 jackson-user...@googlegroups.com. 
>> >> >> > To post to this group, send email to jackso...@googlegroups.com. 
>> >> >> > For m

Re: [jackson-user] Re: How to access default serializer when writing custom serialiser

2017-03-21 Thread Zsolt Balanyi
http://stackoverflow.com/questions/31056215/how-to-access-default-jackson-serialization-in-a-custom-serializer

2017. március 21., kedd 9:16:17 UTC+1 időpontban Zsolt Balanyi a következőt 
írta:
>
> This article points out exactly the fact, that the usage of 
> BeanSerializerModifier makes in unnecessary to use the annotation!
> So I would happily contribute to make the @JsonSerialize smarter. :)
>
> BR, Zsolt
>
> 2017. március 21., kedd 8:25:51 UTC+1 időpontban Zsolt Balanyi a 
> következőt írta:
>>
>> Hi!
>>
>> This is exactly what I was wondering... if there is a way to automate the 
>> default serializer injection, when the custom serializer gets detected.
>> I am also willing to contribute to the code, if I am provided some 
>> guidance.
>>
>> BR, Zsolt
>>
>> 2017. március 20., hétfő 21:24:27 UTC+1 időpontban Tatu Saloranta a 
>> következőt írta:
>>>
>>> Good luck! That approach is used quite a lot so it should work fine. 
>>> Note, too, that it may be combined with ContextualSerializer if you do 
>>> need to access annotations. 
>>> In fact you can use `createContextual()` sometimes to simply decide if 
>>> override is needed at all; if not, return default serializer from that 
>>> method and you are good to go (but if so, remember to delegate call). 
>>>
>>> It would be great to find better ways to allow such "partial" 
>>> overrides, in a more convenient way. 
>>> But until then, Bean(De)SerializerModifier is the way to go. 
>>>
>>> -+ Tatu +- 
>>>
>>>
>>> On Mon, Mar 20, 2017 at 1:08 PM, Zsolt Balanyi  
>>> wrote: 
>>> > Hi! 
>>> > 
>>> > OK, thanks, then I'll go that way! 
>>> > 
>>> > BR, Zsolt 
>>> > 
>>> > 2017. március 20., hétfő 20:13:25 UTC+1 időpontban Tatu Saloranta a 
>>> > következőt írta: 
>>> >> 
>>> >> This can not be done from annotation-based serializer: it will 
>>> >> override default logic. 
>>> >> The only way to access what would otherwise be created/used as the 
>>> >> standard serializer is to register `BeanSerializerModifier`, and 
>>> >> override handling of `modifySerializer`. 
>>> >> 
>>> >> -+ Tatu +- 
>>> >> 
>>> >> 
>>> >> On Mon, Mar 20, 2017 at 11:58 AM, Zsolt Balanyi  
>>>
>>> >> wrote: 
>>> >> > Hi! 
>>> >> > 
>>> >> > What I meant is that I would like to get (or create ) the default 
>>> >> > Jackson 
>>> >> > Serializer for the object being serialized, and store as default. 
>>> >> > Then I could implement serialize as follows: 
>>> >> > 
>>> >> > @Override 
>>> >> > public void serialize(Object o, JsonGenerator jg, 
>>> SerializerProvider sp) 
>>> >> > throws IOException { 
>>> >> >   doMyStuff... 
>>> >> >   default.serialize(o, jg, sp); 
>>> >> > } 
>>> >> > 
>>> >> > The challenge here is that only a no-arg constructor is called for 
>>> the 
>>> >> > serializer if the serializer is used in annotation like this: 
>>> >> > @JsonSerialize(using = UIElementSerializer.class) 
>>> >> > 
>>> >> > BR, Zsolt 
>>> >> > 
>>> >> > 2017. március 20., hétfő 19:21:29 UTC+1 időpontban Tatu Saloranta a 
>>> >> > következőt írta: 
>>> >> >> 
>>> >> >> Not 100% sure I understand the question, but if you want to access 
>>> >> >> information about annotations on property, from your custom 
>>> >> >> serializer, you need to implement `ContextualSerializer`, and then 
>>> its 
>>> >> >> `createContextual()` gets called with `BeanProperty`. 
>>> >> >> `BeanProperty` has accessors for annotation directly; or, you can 
>>> then 
>>> >> >> call `AnnotationIntrospector` (accessible from 
>>> `SerializerProvider` 
>>> >> >> that is also passed). 
>>> >> >> 
>>> >> >> -+ Tatu +- 
>>> >> >> 
>>> >> >> 
>>> >> >> On Mon, Mar 20, 2017 at 5:26 AM, Zsolt Balanyi <
>>> zsolt@gmail.com> 
>>> >> >> wrote: 
>>> >> >> > Hi All! 
>>> >> >> > 
>>> >> >> > But what can I do when I want to use annotation, and I don't 
>>> have 
>>> >> >> > access 
>>> >> >> > to 
>>> >> >> > the mapper? 
>>> >> >> > Eg: 
>>> >> >> > 
>>> >> >> > @JsonSerialize(using = ASerializer.class) 
>>> >> >> > public class AClass { 
>>> >> >> > ... 
>>> >> >> > } 
>>> >> >> > 
>>> >> >> > BR, Zsolt 
>>> >> >> > 
>>> >> >> > 2015. június 23., kedd 16:18:36 UTC+2 időpontban Tim Dudgeon a 
>>> >> >> > következőt 
>>> >> >> > írta: 
>>> >> >> >> 
>>> >> >> >> Hi, 
>>> >> >> >> 
>>> >> >> >> I'm writing a custom serialiizer, extending StdSerializer. 
>>> >> >> >> In the 
>>> >> >> >> public void serialize(MoleculeObject mo, JsonGenerator jg, 
>>> >> >> >> SerializerProvider sp) 
>>> >> >> >> method I need to be able to access the default json 
>>> serialization 
>>> >> >> >> mechanism, but I don't see how to do this. 
>>> >> >> >> I can't call super.serialize() as its abstract, and using 
>>> >> >> >> JsonGenerator.writeObject() or 
>>> >> >> >> SerializerProvider.defaultSerializeValue() 
>>> >> >> >> end up calling my custom serialize() method and end up with 
>>> stack 
>>> >> >> >> overflow. 
>>> >> >> >> 
>>> >> >> >> How should I be doing this? 
>>> >> >> >> 
>>> >> >> >> Tim 
>>> >> >> > 
>>> >> >> > -- 
>>> >> >> > You r