/** * Constructor to use when a custom mapper (usually components * like serializer/deserializer factories that have been configured) * is to be used. * * @param annotationsToUse Sets of annotations (Jackson, JAXB) that provider should * support */ public JacksonJsonProvider(ObjectMapper mapper, Annotations[] annotationsToUse) { super(new JsonMapperConfigurator(mapper, annotationsToUse)); }
@Override protected JsonEndpointConfig _configForWriting(ObjectWriter writer, Annotation[] annotations) { return JsonEndpointConfig.forWriting(writer, annotations, _jsonpFunctionName); }
@Override protected JsonEndpointConfig _configForReading(ObjectReader reader, Annotation[] annotations) { return JsonEndpointConfig.forReading(reader, annotations); }
@Override protected void configureClient(ClientConfig clientConfig) { final JacksonJsonProvider jsonProvider = new JacksonJsonProvider(); jsonProvider.setMapper(configuration.mapper); configuration.clientConfigurator.accept(clientConfig); clientConfig.register(jsonProvider); } };
protected Client initClient(int rt, int ct) { ClientConfig clientConfig = new ClientConfig(); clientConfig.property(ClientProperties.CONNECT_TIMEOUT, ct); clientConfig.property(ClientProperties.READ_TIMEOUT, rt); ClientBuilder.newBuilder().register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); client.register(JacksonFeature.class); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(JacksonUtil.getMapper()); client.register(provider); return client; }
protected ClientBase(ClientConfig config, ConductorClientConfiguration clientConfiguration, ClientHandler handler) { objectMapper = new JsonMapperProvider().get(); JacksonJsonProvider provider = new JacksonJsonProvider(objectMapper); config.getSingletons().add(provider); if (handler == null) { this.client = Client.create(config); } else { this.client = new Client(handler, config); } conductorClientConfiguration = clientConfiguration; payloadStorage = new PayloadStorage(this); }
protected TestModelBase(Class<?> clazz) throws Exception { super(); this.clazz = clazz; context = new JAXBContextResolver().getContext(clazz); mapper = new JacksonJaxbJsonProvider().locateMapper(clazz, MediaType.APPLICATION_JSON_TYPE); }
public static JsonEndpointConfig forWriting(ObjectWriter writer, Annotation[] annotations, String defaultJsonpMethod) { JsonEndpointConfig config = new JsonEndpointConfig(writer.getConfig()); if (defaultJsonpMethod != null) { config._jsonp = new JSONP.Def(defaultJsonpMethod); } return config .add(annotations, true) .initWriter(writer) ; }
public static JsonEndpointConfig forReading(ObjectReader reader, Annotation[] annotations) { return new JsonEndpointConfig(reader.getConfig()) .add(annotations, false) .initReader(reader); }
/** * @param s the JSON representation of the filter * @return the filter * @throws Exception */ public static Filter buildFilter(String s) throws Exception { FilterModel model = getJasonProvider().locateMapper(FilterModel.class, MediaType.APPLICATION_JSON_TYPE).readValue(s, FilterModel.class); return model.build(); }
/** * @deprecated Since 2.2 use {@link #hasMatchingMediaType(MediaType)} instead */ @Deprecated protected boolean isJsonType(MediaType mediaType) { return hasMatchingMediaType(mediaType); } }
@Override public synchronized ObjectMapper getDefaultMapper() { if (_defaultMapper == null) { _defaultMapper = new ObjectMapper(); _setAnnotations(_defaultMapper, _defaultAnnotationsToUse); } return _defaultMapper; }
@Override public Object modifyBeforeWrite(Object value) { return applyJSONP(value); }
@Override public boolean isWriteable(Class<?> type, @Nullable Type genericType, @Nullable Annotation[] annotations, @Nullable MediaType mediaType) { return isProvidable(type) && super.isWriteable(type, genericType, annotations, mediaType); }
@Override public boolean isReadable(Class<?> type, @Nullable Type genericType, @Nullable Annotation[] annotations, @Nullable MediaType mediaType) { return isProvidable(type) && super.isReadable(type, genericType, annotations, mediaType); }
@Override protected AnnotationIntrospector _resolveIntrospectors(Annotations[] annotationsToUse) { // Let's ensure there are no dups there first, filter out nulls ArrayList<AnnotationIntrospector> intr = new ArrayList<AnnotationIntrospector>(); for (Annotations a : annotationsToUse) { if (a != null) { intr.add(_resolveIntrospector(a)); } } int count = intr.size(); if (count == 0) { return AnnotationIntrospector.nopInstance(); } AnnotationIntrospector curr = intr.get(0); for (int i = 1, len = intr.size(); i < len; ++i) { curr = AnnotationIntrospector.pair(curr, intr.get(i)); } return curr; }
@Provides @Singleton public JacksonJsonProvider getJacksonJsonProvider(@Json ObjectMapper objectMapper) { final JacksonJsonProvider provider = new JacksonJsonProvider(); provider.setMapper(objectMapper); return provider; }
protected Client initClient(int rt, int ct) { ClientConfig clientConfig = new ClientConfig(); clientConfig.property(ClientProperties.CONNECT_TIMEOUT, ct); clientConfig.property(ClientProperties.READ_TIMEOUT, rt); ClientBuilder.newBuilder().register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); client.register(JacksonFeature.class); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(); provider.setMapper(JacksonUtil.getMapper()); client.register(provider); return client; }
/** * @param filter the filter * @return the JSON representation of the filter * @throws Exception */ public static String stringifyFilter(final Filter filter) throws Exception { return getJasonProvider().locateMapper(FilterModel.class, MediaType.APPLICATION_JSON_TYPE).writeValueAsString(new FilterModel(filter)); }
/** * Helper method that will ensure that there is a configurable non-default * mapper (constructing an instance if one didn't yet exit), and return * that mapper. */ @Override protected ObjectMapper mapper() { if (_mapper == null) { _mapper = new ObjectMapper(); _setAnnotations(_mapper, _defaultAnnotationsToUse); } return _mapper; }