Tuesday, 15 March 2011

java - Custom MOXyJsonProvider in Jersey 2 not working? -


I was reading more than the answer and the approach I'm trying to do was not matched, so I it shot decided to give a .. I made a feature to disable the default ConfigurableMoxyJsonProvider,

  @Provider public square JsonFeature feature @Override {public boolean configured (last FeatureContext context) {apply Does the last string disableMoxy = CommonProperties.MOXY_JSON_FEATURE_DISABLE + '.' + Context.get Configuration (). GetRuntimeType () Name (). ToLowerCase (); Context.property (disabledMoxy, true); Back true; }}  

I have created a simple custom providers,

  @Provider @Produces (MediaType.APPLICATION_JSON) @Consumes (MediaType.APPLICATION_JSON) Public Class JsonProvider MOXyJsonProvider {@Override protected void preWriteTo (object object, class and lieutenant; ?? gt; type, type generic type, annotation [] annotation, media type media type, multivivalmap & lt; string, object & gt; httpHeaders, Marshall Marshall) Expands in JAXBException {System.out.println ("test"); } @Override protected void preReadFrom (Class & lt; object & gt; type, genericType, annotation [] annotations, MediaType MediaType, MultivaluedMap & LT; string, string & gt; httpHeaders, Unmarshaller unmarshaller) JAXBException {println ( "test ") Throws; }}  

I have registered both;

Register (JasonFeature.class); Register (JsonProvider.class);

And I have a shot with a simple GET request,

  @GET @Path ( "test") public String getTest () {new Return TestObject (); }  

I believe that this should work, but neither the preceding nor the prequel is ever received by applicant. Do I remember any other step? How do I get the fire

find out - anyone that stops it across .. the perfect way to default off,

  public class implements @Provider JsonFeature Feature {@Override public boolean configured (last FeatureContext context) {context.property (CommonProperties.MOXY_JSON_FEATURE_DISABLE_SERVER, truth); Back true; }}  

Then ConfigurableMoxyJsonProvider expands like so;

  @Provider @Produces (MediaType.APPLICATION_JSON) @Consumes (MediaType.APPLICATION_JSON) public class JsonProvider ConfigurableMoxyJsonProvider extends {@Override protected void preWriteTo (object, class of & lt ;? & gt; type, genericType, annotation [] annotations, MediaType MediaType, MultivaluedMap & LT; string, object & gt; httpHeaders, marshaller marshaller) throws JAXBException {println ( "test"); } @Override protected void preReadFrom (Class & lt; object & gt; type, genericType, annotation [] annotations, MediaType MediaType, MultivaluedMap & LT; string, string & gt; httpHeaders, Unmarshaller unmarshaller) JAXBException {println ( "test ") Throws; }}  

No comments:

Post a Comment