List of usage examples for com.fasterxml.jackson.databind.node ObjectNode put
public ObjectNode put(String paramString1, String paramString2)
From source file:org.waarp.common.json.JsonHandler.java
/** * //from www. ja v a 2 s. co m * @param node * @param field * @param value */ public final static void setValue(ObjectNode node, Enum<?> field, byte[] value) { if (value == null || value.length == 0) { return; } node.put(field.name(), value); }
From source file:org.opendaylight.sfc.sbrest.json.ExporterUtil.java
protected static ObjectNode getDataPlaneLocatorObjectNode(DataPlaneLocator dataPlaneLocator) { if (dataPlaneLocator == null) { return null; }/* www . j av a 2s .co m*/ ObjectMapper mapper = new ObjectMapper(); ObjectNode locatorNode = null; if (dataPlaneLocator.getLocatorType() != null) { locatorNode = mapper.createObjectNode(); String type = dataPlaneLocator.getLocatorType().getImplementedInterface().getSimpleName().toLowerCase(); switch (type) { case FUNCTION: Function functionLocator = (Function) dataPlaneLocator.getLocatorType(); locatorNode.put(_FUNCTION_NAME, functionLocator.getFunctionName()); break; case IP: Ip ipLocator = (Ip) dataPlaneLocator.getLocatorType(); if (ipLocator.getIp() != null) { locatorNode.put(_IP, convertIpAddress(ipLocator.getIp())); if (ipLocator.getPort() != null) { locatorNode.put(_PORT, ipLocator.getPort().getValue()); } } break; case LISP: Lisp lispLocator = (Lisp) dataPlaneLocator.getLocatorType(); if (lispLocator.getEid() != null) locatorNode.put(_EID, convertIpAddress(lispLocator.getEid())); break; case MAC: Mac macLocator = (Mac) dataPlaneLocator.getLocatorType(); if (macLocator.getMac() != null) locatorNode.put(_MAC, macLocator.getMac().getValue()); locatorNode.put(_VLAN_ID, macLocator.getVlanId()); } } if (dataPlaneLocator.getTransport() != null) { if (locatorNode == null) { locatorNode = mapper.createObjectNode(); } locatorNode.put(_TRANSPORT, getDataPlaneLocatorTransport(dataPlaneLocator)); } return locatorNode; }
From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java
private static PatchMessage<DiffMatchPatchEdit> sendAddDoc(final String docId, final String clientId, final EmbeddedChannel ch) { final ObjectNode docMsg = message("add"); docMsg.put("msgType", "add"); docMsg.put("id", docId); docMsg.put("clientId", clientId); return fromJson(writeFrame(docMsg.toString(), ch), DiffMatchPatchMessage.class); }
From source file:org.apache.asterix.api.http.server.ResultUtil.java
public static ObjectNode getErrorResponse(int errorCode, String errorMessage, String errorSummary, String errorStackTrace) { ObjectMapper om = new ObjectMapper(); ObjectNode errorResp = om.createObjectNode(); ArrayNode errorArray = om.createArrayNode(); errorArray.add(errorCode);//from w w w . j a v a2 s .c om errorArray.add(errorMessage); errorResp.set("error-code", errorArray); if (!"".equals(errorSummary)) { errorResp.put("summary", errorSummary); } else { //parse exception errorResp.put("summary", errorMessage); } errorResp.put("stacktrace", errorStackTrace); return errorResp; }
From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java
private static JsonNode sendAddDocMsg(final String docId, final String clientId, final String content, final EmbeddedChannel ch) { final ObjectNode docMsg = message("add"); docMsg.put("msgType", "add"); docMsg.put("id", docId); docMsg.put("clientId", clientId); docMsg.put("content", content); return writeTextFrame(docMsg.toString(), ch); }
From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java
private static PatchMessage<DiffMatchPatchEdit> sendAddDoc(final String docId, final String clientId, final String content, final EmbeddedChannel ch) { final ObjectNode docMsg = message("add"); docMsg.put("msgType", "add"); docMsg.put("id", docId); docMsg.put("clientId", clientId); docMsg.put("content", content); return fromJson(writeFrame(docMsg.toString(), ch), DiffMatchPatchMessage.class); }
From source file:org.jboss.aerogear.sync.server.netty.DiffSyncHandlerTest.java
private static ObjectNode message(final String type) { final ObjectNode jsonNode = JsonMapper.newObjectNode(); jsonNode.put("msgType", type); return jsonNode; }
From source file:com.baasbox.controllers.Social.java
/** * Login the user through socialnetwork specified * //from www .ja v a 2 s . c o m * An oauth_token and oauth_secret provided by oauth steps * are mandatory * @param socialNetwork the social network name (facebook,google) * @return 200 status code with the X-BB-SESSION token for further calls */ @With({ AdminCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result loginWith(String socialNetwork) { String appcode = (String) ctx().args.get("appcode"); //after this call, db connection is lost! SocialLoginService sc = SocialLoginService.by(socialNetwork, appcode); Token t = extractOAuthTokensFromRequest(request()); if (t == null) { return badRequest( String.format("Both %s and %s should be specified as query parameters or in the json body", OAUTH_TOKEN, OAUTH_SECRET)); } UserInfo result = null; try { if (sc.validationRequest(t.getToken())) { result = sc.getUserInfo(t); } else { return badRequest("Provided token is not valid"); } } catch (BaasBoxSocialException e1) { return badRequest(e1.getError()); } catch (BaasBoxSocialTokenValidationException e2) { return badRequest("Unable to validate provided token"); } if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("UserInfo received: " + result.toString()); result.setFrom(socialNetwork); result.setToken(t.getToken()); //Setting token as secret for one-token only social networks result.setSecret( t.getSecret() != null && StringUtils.isNotEmpty(t.getSecret()) ? t.getSecret() : t.getToken()); UserDao userDao = UserDao.getInstance(); ODocument existingUser = null; try { existingUser = userDao.getBySocialUserId(result); } catch (SqlInjectionException sie) { return internalServerError(ExceptionUtils.getMessage(sie)); } if (existingUser != null) { String username = null; try { username = UserService.getUsernameByProfile(existingUser); if (username == null) { throw new InvalidModelException("username for profile is null"); } } catch (InvalidModelException e) { internalServerError("unable to login with " + socialNetwork + " : " + ExceptionUtils.getMessage(e)); } String password = UserService.generateFakeUserPassword(username, (Date) existingUser.field(UserDao.USER_SIGNUP_DATE)); ImmutableMap<SessionKeys, ? extends Object> sessionObject = SessionTokenProvider .getSessionTokenProvider().setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); ObjectNode on = Json.newObject(); if (existingUser != null) { on = (ObjectNode) Json.parse(User.prepareResponseToJson(existingUser)); } on.put(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); return ok(on); } else { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("User does not exists with tokens...trying to create"); String username = UUID.randomUUID().toString(); Date signupDate = new Date(); try { String password = UserService.generateFakeUserPassword(username, signupDate); JsonNode privateData = null; if (result.getAdditionalData() != null && !result.getAdditionalData().isEmpty()) { privateData = Json.toJson(result.getAdditionalData()); } UserService.signUp(username, password, signupDate, null, privateData, null, null, true); ODocument profile = UserService.getUserProfilebyUsername(username); UserService.addSocialLoginTokens(profile, result); ImmutableMap<SessionKeys, ? extends Object> sessionObject = SessionTokenProvider .getSessionTokenProvider().setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); ObjectNode on = Json.newObject(); if (profile != null) { on = (ObjectNode) Json.parse(User.prepareResponseToJson(profile)); } on.put(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); return ok(on); } catch (Exception uaee) { return internalServerError(ExceptionUtils.getMessage(uaee)); } } }
From source file:controllers.chqbll.AjaxService.java
public static Result transSteps(String fromStep, String toStep) { ObjectNode result = Json.newObject(); ChqbllStep fs = ChqbllStep.InPortfolio; ChqbllStep ts = null;/*from w w w.j av a2s . com*/ try { fs = ChqbllStep.valueOf(fromStep); } catch (Exception e) { } try { ts = ChqbllStep.valueOf(toStep); } catch (Exception e) { } Map<String, String> targetSteps = ChqbllStep.targetOptions(fromStep); result.put("steps", Json.toJson(targetSteps)); result.put("module", Json.toJson(ChqbllStep.findRefModule(fs, ts, targetSteps))); return ok(result); }
From source file:com.google.openrtb.json.OpenRtbJsonTest.java
private static String cleanupIdField(final String jsonString) throws IOException { ObjectMapper mapper = new ObjectMapper(); ObjectNode json = mapper.readValue(jsonString, ObjectNode.class); json.put("id", "1"); return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); }