protected void writeJson(JsonMapper jsonMapper, OutputStream os, Object responseObject, ApiRequest request) throws IOException { jsonMapper.writeValue(os, responseObject); }
public EscapeForwardSlash() { _asciiEscapes = standardAsciiEscapesForJSON(); _asciiEscapes['/'] = CharacterEscapes.ESCAPE_CUSTOM; }
public ActionLinksMapper() { init(); }
@Override public Object doWithLock() { if ((roles == null || roles.isEmpty()) && accountId == null) { throw new ValidationErrorException(ValidationErrorCodes.MISSING_REQUIRED, "MustSpecifyAccountIdOrRole"); } try { jsonMapper.readValue( String.valueOf(requestObject.get(DEFINITION_FIELD)).getBytes("UTF-8"), SchemaImpl.class); } catch (Exception e) { throw new ValidationErrorException(ValidationErrorCodes.INVALID_FORMAT, DEFINITION_FIELD); } return filter.callSuperCreate(type, request, next); } });
@Bean HtmlResponseWriter HtmlResponseWriter(ExtensionManagerImpl em) { HtmlResponseWriter writer = EMUtils.add(em, ApiRequestHandler.class, new HtmlResponseWriter()); JacksonMapper jacksonMapper = new JacksonMapper(); jacksonMapper.setEscapeForwardSlashes(true); jacksonMapper.init(); writer.setJsonMapper(jacksonMapper); return writer; }
Map<String, Object> obj = jsonMapper.convertValue(objectToPlace, Map.class); jsonMapper.writeValue(os, obj); data.put(fieldForObject, os.toString()); } catch (IOException e) {
@Bean JacksonMapper JacksonMapper() { return new JacksonMapper(); }
@PostConstruct public void init() { SimpleModule module = getModule(); SimpleDateFormat df = new SimpleDateFormat(DateUtils.DATE_FORMAT); df.setTimeZone(TimeZone.getTimeZone("GMT")); mapper = new ObjectMapper(); mapper.setDateFormat(df); mapper.registerModule(new JaxbAnnotationModule()); mapper.registerModule(module); mapper.getFactory().configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); if (escapeForwardSlashes) { mapper.getFactory().setCharacterEscapes(new EscapeForwardSlash()); } }
Map<String, Object> resourceData = jsonMapper.convertValue(resource, Map.class);; if (request.getOptions().get("_actionLinks") != null) { data.put("actionLinks", resourceData.remove("actions"));
mapper = new JacksonMapper(); SimpleModule simpleModule = new SimpleModule( "SimpleModule", new Version(1,0,0,null) ); simpleModule.addSerializer( JavassistLazyInitializer.class, new HibernateLazyInitializerSerializer() ); mapper.registerModule(simpleModule);
protected Object getObject(ApiRequest request) throws IOException { if (!RequestUtils.mayHaveBody(request.getMethod())) return null; if (!shouldBeParsed(request)) { return null; } InputStream is = request.getInputStream(); if (is == null) { return null; } byte[] content = IOUtils.toByteArray(is); if (content.length == 0) return null; try { Object body = jsonMarshaller.readValue(content); if (isAllowedType(body)) { return body; } } catch (IOException e) { throw new ClientVisibleException(ResponseCodes.BAD_REQUEST, ValidationErrorCodes.INVALID_BODY_CONTENT); } return null; }
SchemaImpl newSchema = jsonMapper.readValue(dynamicSchema.getDefinition().getBytes("UTF-8"), SchemaImpl.class); newSchema.setId(dynamicSchema.getName()); return newSchema; SchemaImpl newSchema = jsonMapper.readValue(dynamicSchema.getDefinition().getBytes("UTF-8"), SchemaImpl.class); newSchema.setName(dynamicSchema.getName()); SchemaImpl mergedSchema = new SchemaImpl((SchemaImpl)parentSchema);