List of usage examples for com.fasterxml.jackson.databind ObjectMapper enable
public ObjectMapper enable(SerializationFeature f)
From source file:net.proest.librepilot.web.handler.DefinitionHandler.java
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setCharacterEncoding("utf-8"); response.setStatus(HttpServletResponse.SC_OK); PrintWriter out = response.getWriter(); List<String> targetObjects = Arrays.asList(target.split("/")); SortedMap<String, UAVTalkXMLObject> objects = new TreeMap<>(); for (UAVTalkXMLObject xmlObj : mFcDevice.getObjectTree().getXmlObjects().values()) { if (targetObjects.size() == 0 || targetObjects.contains(xmlObj.getName())) { if (mShowSettings && xmlObj.isSettings() || mShowState && !xmlObj.isSettings()) { objects.put(xmlObj.getName(), xmlObj); }// w w w.ja va 2 s . c o m } } String callback = request.getParameter("callback"); if (callback != null) { response.setContentType("application/javascript"); out.println(callback + "("); } else { response.setContentType("application/json"); } ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); out.println(mapper.writeValueAsString(objects)); if (callback != null) { out.print(")"); } baseRequest.setHandled(true); }
From source file:uk.ac.surrey.ee.iot.fiware.ngsi9.notify.NotifierAtSubscription.java
@Override public void run() { DiscoveryContextAvailabilityRequest discReq = new DiscoveryContextAvailabilityRequest(); discReq.getEntityId().addAll(subsReq.getEntityId()); discReq.getAttribute().addAll(subsReq.getAttribute()); discReq.getRestriction().setAttributeExpression(subsReq.getRestriction().getAttributeExpression()); discReq.getRestriction().getOperationScope().addAll(subsReq.getRestriction().getOperationScope()); Resource02_Discovery discRes = new Resource02_Discovery(); DiscoveryContextAvailabilityResponse dcar = discRes.parseDiscoveryRequest(discReq); NotifyContextAvailabilityRequest ncar = new NotifyContextAvailabilityRequest(); ncar.getContextRegistrationResponse().addAll(dcar.getContextRegistrationResponse()); ncar.setSubscriptionId(subsReq.getSubscriptionId()); //marshal request // NotifyMarshaller nm = new NotifyMarshaller(); String notifMsg = null;// ww w. j a v a 2s . co m // try { // notifMsg = nm.marshallRequest(ncar); // } catch (JAXBException ex) { // Logger.getLogger(NotifierAtSubscription.class.getName()).log(Level.SEVERE, null, ex); // } ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); try { notifMsg = objectMapper.writeValueAsString(ncar); } catch (JsonProcessingException ex) { Logger.getLogger(Resource02_Discovery.class.getName()).log(Level.SEVERE, null, ex); } //notify subscriber String callbackUrl = subsReq.getReference(); ClientResource ngsiClient = new ClientResource(callbackUrl); ngsiClient.accept(MediaType.APPLICATION_JSON); String payload = notifMsg; try { ngsiClient.post(payload).write(System.out); //Response is not handled for now } catch (IOException ex) { Logger.getLogger(NotifierAtSubscription.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.helpmobile.test.RestTest.java
@Test public void testRegister() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); User testUser = new User(); testUser.setName("Bob"); testUser.setId("12345"); testUser.setPassword("test"); testUser.setCountryOrigin(Country.ARUBA); testUser.setDegreeLevel(DegreeLevel.POSTGRADUATE); testUser.setGender(Gender.MALE);//from ww w . ja v a 2s. c o m testUser.setFirstLanguage(Language.ALBANIAN); testUser.setDob(new Date()); String json = mapper.writeValueAsString(testUser); RestAccess restAccess = new RestAccess(); System.out.println(json); //String response = restAccess.doJsonRequest("student/register", json, "POST"); //System.out.println(response); }
From source file:org.efaps.rest.AbstractRest.java
/** * Gets the JSON reply./* ww w. j av a 2 s. c om*/ * * @param _jsonObject the _json object * @return the JSON reply * @throws JsonProcessingException the json processing exception */ protected String getJSONReply(final Object _jsonObject) { String ret = ""; final ObjectMapper mapper = new ObjectMapper(); if (LOG.isDebugEnabled()) { mapper.enable(SerializationFeature.INDENT_OUTPUT); } mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.registerModule(new JodaModule()); try { ret = mapper.writeValueAsString(_jsonObject); } catch (final JsonProcessingException e) { LOG.error("Catched JsonProcessingException", e); } return ret; }
From source file:uk.ac.surrey.ee.iot.fiware.ngsi9.notify.NotifierAtRegistration.java
@Override public void run() { List<SubscribeContextAvailabilityRequest> subReq = SubscriptionStoreAccess.matchRegToSubs(regReq); int subReqListSize = subReq.size(); List<ContextRegistration> cr = regReq.getContextRegistration(); //iterate through each subscription for (int i = 0; i < subReqListSize; i++) { NotifyContextAvailabilityRequest ncar = new NotifyContextAvailabilityRequest(); List<ContextRegistrationResponse> crrl = new ArrayList<>(); int crListSize = cr.size(); //iterate through each context registration for (int j = 0; j < crListSize; j++) { ContextRegistrationResponse crr = new ContextRegistrationResponse(); crr.setContextRegistration(cr.get(j)); crrl.add(crr);/*from w ww .j ava2s . c o m*/ } ncar.getContextRegistrationResponse().addAll(crrl); ncar.setSubscriptionId(subReq.get(i).getSubscriptionId()); //serialize request String notifMsg = null; ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); try { notifMsg = objectMapper.writeValueAsString(ncar); } catch (JsonProcessingException ex) { Logger.getLogger(Resource02_Discovery.class.getName()).log(Level.SEVERE, null, ex); } //notify subscriber String callbackUrl = subReq.get(i).getReference(); ClientResource ngsiClient = new ClientResource(callbackUrl); ngsiClient.accept(MediaType.APPLICATION_JSON); String payload = notifMsg; try { ngsiClient.post(payload).write(System.out); //Response is not handled for now } catch (IOException ex) { Logger.getLogger(NotifierAtRegistration.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.wildfly.swarm.plugin.fractionlist.FractionListMojo.java
protected void generateJSON(Set<FractionMetadata> fractions) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); File outFile = new File(this.project.getBuild().getOutputDirectory(), "fraction-list.json"); try {//from www .j a v a 2 s.c om mapper.writeValue(outFile, fractions); } catch (IOException e) { e.printStackTrace(); } org.apache.maven.artifact.DefaultArtifact artifact = new org.apache.maven.artifact.DefaultArtifact( this.project.getGroupId(), this.project.getArtifactId(), this.project.getVersion(), "compile", "json", "", new DefaultArtifactHandler("json")); artifact.setFile(outFile); this.project.addAttachedArtifact(artifact); }
From source file:com.frank.search.solr.core.schema.SolrSchemaWriter.java
SchemaDefinition loadExistingSchema(String collectionName) { try {/* w w w . java2 s . c o m*/ SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrClient(collectionName)); if (response != null && response.getNode("schema") != null) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.AUTO_DETECT_CREATORS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class); } return null; } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e); } catch (SolrException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } }
From source file:org.springframework.data.solr.core.schema.SolrSchemaWriter.java
SchemaDefinition loadExistingSchema(String collectionName) { try {/*from ww w.j a v a 2 s. c o m*/ SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrServer(collectionName)); if (response != null && response.getNode("schema") != null) { ObjectMapper mapper = new ObjectMapper(); mapper.enable(MapperFeature.AUTO_DETECT_CREATORS); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class); } return null; } catch (SolrServerException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } catch (IOException e) { throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e); } catch (SolrException e) { throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e)); } }
From source file:com.hp.autonomy.frontend.find.idol.beanconfiguration.IdolConfiguration.java
@SuppressWarnings("SpringJavaAutowiringInspection") @Bean//from w w w . j a va 2 s. co m @Autowired public ObjectMapper jacksonObjectMapper(final Jackson2ObjectMapperBuilder builder) { final ObjectMapper objectMapper = builder.createXmlMapper(false).build(); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); objectMapper.addMixIn(ServerConfig.class, ConfigurationFilterMixin.class); objectMapper.addMixIn(ViewConfig.class, ConfigurationFilterMixin.class); return objectMapper; }