writer = writer.withType(rootType);
@Override public ObjectWriter load(Class<?> key) throws Exception { return objectWriter.withType(key); } });
@Override public ObjectWriter load(Class<?> key) throws Exception { return objectWriter.withType(key); } });
public <O> Builder addRoute(String name, Endpoint endpoint, PermissionFactory permissionFactory, Class<O> outputType, final MatchedEntityRoute<Void, O> route) { routes.add(new StdJsonProducerEntityRoute<O>(name, outputType, writer.withType(outputType), endpoint, permissionFactory, registry) { @Override protected Optional<O> doRoute(RestxRequest restxRequest, RestxResponse response, RestxRequestMatch match, Void i) throws IOException { return route.route(restxRequest, match, i); } }); return this; }
public <O> Builder addRoute(String name, Endpoint endpoint, PermissionFactory permissionFactory, Class<O> outputType, final MatchedEntityRoute<Void, O> route) { routes.add(new StdJsonProducerEntityRoute<O>(name, outputType, writer.withType(outputType), endpoint, permissionFactory, registry) { @Override protected Optional<O> doRoute(RestxRequest restxRequest, RestxResponse response, RestxRequestMatch match, Void i) throws IOException { return route.route(restxRequest, match, i); } }); return this; }
/** * Method that will construct a new instance that uses specific type * as the root type for serialization, instead of runtime dynamic * type of the root object itself. */ public ObjectWriter withType(Class<?> rootType) { return withType(_config.constructType(rootType)); }
/** * Method that will construct a new instance that uses specific type * as the root type for serialization, instead of runtime dynamic * type of the root object itself. */ public ObjectWriter withType(Class<?> rootType) { return withType(_config.constructType(rootType)); }
@Override public String requirementsAsJson() { FabricRequirements dto = requirements(); try { return getObjectMapper() .writerWithDefaultPrettyPrinter() .withType(FabricRequirements.class) .writeValueAsString(dto); } catch (JsonProcessingException e) { throw new RuntimeException("Error writing data as json", e); } }
@Override public String fabricStatusAsJson() { FabricStatusDTO dto = fabricStatus(); if (dto != null) { try { return getObjectMapper() .writerWithDefaultPrettyPrinter() .withType(FabricStatusDTO.class) .writeValueAsString(dto); } catch (JsonProcessingException e) { throw new RuntimeException("Error writing data as json", e); } } else { return null; } }
@Override public <T> Optional<? extends EntityResponseWriter<T>> mayBuildFor(Type valueType, String contentType) { if (!contentType.toLowerCase(Locale.ENGLISH).startsWith("application/json")) { return Optional.absent(); } Class<?> clazz = getCTJacksonViewClass(valueType, contentType, Views.Transient.class); ObjectWriter writer = objectWriter.withView(clazz); if (valueType instanceof ParameterizedType) { /* we set the type on writer only for parameterized types: * if we set it for regular types, jackson will build the serializer based on this type, and not the * instance type, making polymorphic returns broken. * For parameterized types it helps Jackson which otherwise tries to guess the serializer based on * value.getClass() which doesn't return type parameters information due to Java erasure. */ writer = writer.withType(TypeFactory.defaultInstance().constructType(valueType)); } return Optional.of(JsonEntityResponseWriter.<T>using(valueType, writer)); } };
public ObjectWriter withType(TypeReference<?> rootType) { return withType(_config.getTypeFactory().constructType(rootType.getType())); }
@Override public <T> Optional<? extends EntityResponseWriter<T>> mayBuildFor(Type valueType, String contentType) { if (!contentType.toLowerCase(Locale.ENGLISH).startsWith("application/json")) { return Optional.absent(); } Class<?> clazz = getCTJacksonViewClass(valueType, contentType, Views.Transient.class); ObjectWriter writer = objectWriter.withView(clazz); if (valueType instanceof ParameterizedType) { /* we set the type on writer only for parameterized types: * if we set it for regular types, jackson will build the serializer based on this type, and not the * instance type, making polymorphic returns broken. * For parameterized types it helps Jackson which otherwise tries to guess the serializer based on * value.getClass() which doesn't return type parameters information due to Java erasure. */ writer = writer.withType(TypeFactory.defaultInstance().constructType(valueType)); } return Optional.of(JsonEntityResponseWriter.<T>using(valueType, writer)); } };
public ObjectWriter withType(TypeReference<?> rootType) { return withType(_config.getTypeFactory().constructType(rootType.getType())); }
@Override public String autoScaleStatusAsJson() { AutoScaleStatus dto = autoScaleStatus(); if (dto != null) { try { return getObjectMapper() .writerWithDefaultPrettyPrinter() .withType(AutoScaleStatus.class) .writeValueAsString(dto); } catch (JsonProcessingException e) { throw new RuntimeException("Error writing data as json", e); } } else { return null; } }
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class) .withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers);
writers.put(InstanceInfo.class, mapper.writer().withType(InstanceInfo.class) .withRootName("instance")); writers.put(Application.class, mapper.writer().withType(Application.class) .withRootName("application")); writers.put(Applications.class, mapper.writer().withType(Applications.class) .withRootName("applications")); setField("objectWriterByClass", writers);
public JacksonColumnMapper() { final ObjectMapper mapper; try { final ObjectMapperFactoryBean omfb = new ObjectMapperFactoryBean(); omfb.afterPropertiesSet(); mapper = omfb.getObject(); } catch (Exception e) { throw new RuntimeException("Failed to create ObjectMapper", e); } customizeObjectMapper(mapper); this.objectWriter = this.createObjectWriter(mapper).withType(JsonWrapper.class); this.objectReader = this.createObjectReader(mapper).withType(JsonWrapper.class); }
public JacksonColumnMapper() { final ObjectMapper mapper; try { final ObjectMapperFactoryBean omfb = new ObjectMapperFactoryBean(); omfb.afterPropertiesSet(); mapper = omfb.getObject(); } catch (Exception e) { throw new RuntimeException("Failed to create ObjectMapper", e); } customizeObjectMapper(mapper); this.objectWriter = this.createObjectWriter(mapper).withType(JsonWrapper.class); this.objectReader = this.createObjectReader(mapper).withType(JsonWrapper.class); }
objectWriter = objectWriter.withType(javaType);
writer = writer.withType(rootType);