List of usage examples for com.fasterxml.jackson.databind JsonNode toString
public abstract String toString();
From source file:org.gravidence.gravifon.filter.FilterUtils.java
/** * Serializes entity to JSON {@link String}.<p> * Sensitive information is replaced by <code>***</code>. Logs serialization error if such one happens. * //w w w . j a v a2 s .co m * @param entity entity * @param logger logger instance * @return <ul> * <li>serialized entity in successful case</li> * <li>{@link #NO_ENTITY} in case the supplied <code>entity</code> argument is <code>null</code></li> * </ul> */ public static String entityToString(Object entity, Logger logger) { String result; if (entity == null) { result = NO_ENTITY; } else { JsonNode root = SharedInstanceHolder.OBJECT_MAPPER.valueToTree(entity); hideSensitiveInformation(root, "password"); result = root.toString(); } return result; }
From source file:org.gravidence.gravifon.filter.FilterUtils.java
/** * Serializes entity to {@link String}.<p> * Sensitive information is replaced by <code>***</code>. * // w w w . j a va2s. co m * @param entity entity * @param logger logger instance * @return <ul> * <li>serialized entity in successful case</li> * <li>{@link #NO_ENTITY} in case the supplied <code>entity</code> argument is <code>null</code></li> * <li>{@link #CORRUPTED_ENTITY} in case of deserialization error</li> * </ul> */ public static String entityToString(byte[] entity, Logger logger) { String result; if (entity == null) { result = NO_ENTITY; } else { try { JsonNode root = SharedInstanceHolder.OBJECT_MAPPER.readTree(entity); hideSensitiveInformation(root, "password"); result = root.toString(); } catch (IOException ex) { logger.error("Failed to deserialize entity", ex); result = CORRUPTED_ENTITY; } } return result; }
From source file:com.meetingninja.csse.database.AgendaDatabaseAdapter.java
public static Agenda parseAgenda(JsonNode agendaNode) throws JsonParseException, JsonMappingException, IOException { return MAPPER.readValue(agendaNode.toString(), Agenda.class); }
From source file:com.xively.client.http.util.ParserUtil.java
public static <T extends DomainObject> Collection<T> toConnectedObjects(String body, Class elementType) { log.debug(String.format("Parsing string to objects: %s", body)); Collection<T> objs;// ww w . j av a2s.c o m CollectionType collectionType = TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, elementType); try { JsonNode node = getObjectMapper().reader().readTree(body); JsonNode total = node.get("totalResults"); if (total != null) { JsonNode results = node.get("results"); objs = getObjectMapper().readValue(results.toString(), collectionType); log.debug(String.format("Parsed string to %s objects", total)); } else { objs = getObjectMapper().readValue(body, collectionType); } } catch (IOException e) { throw new ParseToObjectException(String.format("Unable to parse [%s] to %s.", body, elementType), e); } return objs; }
From source file:org.flowable.app.service.editor.DecisionTableModelConversionUtil.java
public static Model convertModel(Model decisionTableModel) { if (StringUtils.isNotEmpty(decisionTableModel.getModelEditorJson())) { try {// w w w . j a v a2 s . com ObjectMapper objectMapper = new ObjectMapper(); JsonNode decisionTableNode = objectMapper.readTree(decisionTableModel.getModelEditorJson()); DmnJsonConverterUtil.migrateModel(decisionTableNode, objectMapper); // replace editor json decisionTableModel.setModelEditorJson(decisionTableNode.toString()); } catch (Exception e) { throw new InternalServerErrorException(String.format( "Error converting decision table %s to new model version", decisionTableModel.getName())); } } return decisionTableModel; }
From source file:org.flowable.ui.modeler.service.DecisionTableModelConversionUtil.java
public static Model convertModelToV3(Model decisionTableModel) { if (StringUtils.isNotEmpty(decisionTableModel.getModelEditorJson())) { try {// w ww. j av a 2 s .co m ObjectMapper objectMapper = new ObjectMapper(); JsonNode decisionTableNode = objectMapper.readTree(decisionTableModel.getModelEditorJson()); DmnJsonConverterUtil.migrateModelV3(decisionTableNode, objectMapper); // replace editor json decisionTableModel.setModelEditorJson(decisionTableNode.toString()); } catch (Exception e) { throw new InternalServerErrorException( String.format("Error converting decision table %s to new model version", decisionTableModel.getName()), e); } } return decisionTableModel; }
From source file:org.ocsoft.olivia.core.OliviaInitializer.java
private static void initializeAssociations() { //?????/* w ww. j ava2 s. c o m*/ String defaultAssociations = InitializeUtils.readDefaultAssociations(); //?? OliviaConfig userConfig = Olivia.getConfig().getUser(); try { //??? if (defaultAssociations != null) Olivia.getAssociation().loadStateFromJson(defaultAssociations); //????? JsonNode userAssociations = userConfig.get(BasicUserConfigDef.ASSOCITAITONS.getConfigKey()); if (userAssociations != null && userAssociations.size() != 0) { Olivia.getAssociation().putAllFromJson(userAssociations.toString()); } } catch (IOException e) { OliviaLogger.catchException(e); } }
From source file:models.NasaRegistration.java
public static String getUserInfo(String userName, String password) { List<NasaRegistration> allUsers = new ArrayList<NasaRegistration>(); String GET_IND_USER_DATA = "http://einstein.sv.cmu.edu:9000/getContestUser/"; GET_IND_USER_DATA = GET_IND_USER_DATA + userName + '/' + password + '/' + "json"; // Call the API to get the json string JsonNode usersNode = APICall.callAPI(GET_IND_USER_DATA); System.out.println("Output1:" + GET_IND_USER_DATA); System.out.println("Check:" + usersNode.toString()); // if no value is returned or error or is not json array if (usersNode == null || usersNode.has("error")) { System.out.println("inside userNode check"); return null; }//from www. j a v a 2s .com System.out.println("userName response:" + usersNode.get("userName")); System.out.println("userName:" + userName); System.out.println("password:" + usersNode.get("password")); if (usersNode.get("userName").textValue().equals(userName) && usersNode.get("password").textValue().equals(password)) { System.out.println("Comes inside the if block"); return usersNode.get("firstName").textValue(); } else { System.out.println("Does not come inside the if clause"); return null; } }
From source file:me.tfeng.play.avro.JsonIpcController.java
private static Object getRequest(Responder responder, Message message, byte[] data) throws IOException { Schema schema = message.getRequest(); if (ArrayUtils.isEmpty(data)) { // The method takes no argument; use empty data. data = "{}".getBytes(Constants.UTF8); }/*from w w w . j a v a 2 s . c o m*/ JsonNode node = Json.parse(new ByteArrayInputStream(data)); node = AvroHelper.convertFromSimpleRecord(schema, node); return responder.readRequest(message.getRequest(), message.getRequest(), DecoderFactory.get().jsonDecoder(schema, node.toString())); }
From source file:me.tfeng.play.avro.AvroHelper.java
public static String convertToSimpleRecord(Schema schema, String json) throws IOException { if (json.isEmpty()) { return json; }/*from w w w . j ava2 s . c om*/ JsonNode node = Json.parse(json); node = convertToSimpleRecord(schema, node); return node.toString(); }