On Tue, Nov 14, 2017 at 6:22 PM, Kean Erickson <[email protected]> wrote:
> Hey there Tatu,
>
>
> So after adding a provider class extending JacksonJaxbJsonProvider, I've had
> success in producing JSONObjects over GET requests, but there's still some
> trouble still with interpreting POSTed json in requests as JSONObject. I was
> curious, should writing a custom MessageBodyReader still be necessary with
> JsonOrgModule in use?

It should work just fine for GETs, POSTs and PUTs. Should not require
custom MessageBodyReader.

>
>
> /* Application logic.. */
>
> JacksonConfigFeature jsonJacksonFeature = new JacksonConfigFeature();
> singletons.add(jsonJacksonFeature);
>
>
> /* Jackson feature class.. */
>
> @Provider
> public final class JacksonConfigFeature implements Feature {
>
>     @Override
>     public boolean configure(final FeatureContext context) {
>         context.register(JacksonConfigProvider.class);
>         return true;
>     }
> }
>
>
> /* Config provider class.. */
>
> @Provider
> @Produces(MediaType.APPLICATION_JSON)
> public class JacksonConfigProvider extends JacksonJaxbJsonProvider  {
>
>     private static ObjectMapper mapper = new ObjectMapper();
>     static {
>         mapper.registerModule(new JaxbAnnotationModule());
>         mapper.registerModule(new JsonOrgModule());
>      }
>
>     public JacksonConfigProvider() {
>         setMapper(mapper);
>     }
> }
>
>
> /* Field in my DTO */
> @XmlElement private JSONObject json;
>
>
> I removed the implements ContextResolver<ObjectMapper> logic as it didn't
> seem to be making a difference--is it necessary? Having one seems to always
> result in JSONObject getting output as string--this was my original problem.

It has been a while since I had to last manually set things up so
unfortunately I don't know.
But I think any datatype module should have similar issues so when
searching for solutions
(StackOverflow is often a good resource), may want to see if there are
questions about
more popular modules like Joda, Guava or Java8 date/time modules.

Or more generally questions about injecting/initializing ObjectMapper to use.
One trick is to get access to `ObjectMapper` framework uses and
register module on that:
this actually works as mapper is mutable before being used.
So it may be possible to inject `ObjectMapper` on some entity you
control, modify that,
instead of trying to do the reverse.

-+ Tatu +-

>
>
> Cheers,
> -Kean
>
> On Mon, Nov 13, 2017 at 1:33 PM, Tatu Saloranta <[email protected]> wrote:
>>
>> Ok. If so it might make sense to first make sure that framework is
>> using properly configured mapper.
>> One way would be to create a simple stand-alone test with POJO,
>> outside of framework (JAX-RS?).
>> If I understood situation correctly it should just work. One thing I
>> don't know is why value would be serialized
>> as empty String -- I don't see how Jackson would ever produce that.
>>
>> Anyway: if stand-alone case fails as explained I'd like an issue filed
>> for the module since this use case
>> (reading JSON into org.json model; writing JSON out of org.json model)
>> is what module was written for.
>> So it should really "just work".
>>
>> -+ Tatu +-
>>
> --
> 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.

Reply via email to