/** * Method that will construct an ArrayNode and add it as a * field of this ObjectNode, replacing old value, if any. * * @return Newly constructed ArrayNode (NOT the old value, * which could be of any type) */ public ArrayNode putArray(String fieldName) { ArrayNode n = arrayNode(); _put(fieldName, n); return n; }
/** * Method that will construct an ArrayNode and add it as a * field of this ObjectNode, replacing old value, if any. * * @return Newly constructed ArrayNode (NOT the old value, * which could be of any type) */ public ArrayNode putArray(String fieldName) { ArrayNode n = arrayNode(); _put(fieldName, n); return n; }
/** * Method that will construct an ArrayNode and add it as a * field of this ObjectNode, replacing old value, if any. * * @return Newly constructed ArrayNode (NOT the old value, * which could be of any type) */ public ArrayNode putArray(String fieldName) { ArrayNode n = arrayNode(); _put(fieldName, n); return n; }
/** * Method that will construct an ArrayNode and add it as a * field of this ObjectNode, replacing old value, if any. * * @return Newly constructed ArrayNode (NOT the old value, * which could be of any type) */ public ArrayNode putArray(String fieldName) { ArrayNode n = arrayNode(); _put(fieldName, n); return n; }
/** * Method that will construct an ArrayNode and add it as a * field of this ObjectNode, replacing old value, if any. * * @return Newly constructed ArrayNode (NOT the old value, * which could be of any type) */ public ArrayNode putArray(String fieldName) { ArrayNode n = arrayNode(); _put(fieldName, n); return n; }
@Test public void testIDAssignment() throws JsonProcessingException, IOException { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); beacon.put("sessionID", "" + Long.toString(Beacon.REQUEST_NEW_SESSION_ID_MARKER, 16)); beacon.put("tabID", "" + Long.toString(Beacon.REQUEST_NEW_TAB_ID_MARKER, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); String beaconJson = beacon.toString(); String responseJson = dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(0)).addDefaultData(any(DefaultData.class)); JsonNode response = (new ObjectMapper()).readTree(responseJson); assertThat(response, instanceOf(ObjectNode.class)); assertThat(response.get("sessionID").asText(), notNullValue()); assertThat(response.get("tabID").asText(), notNullValue()); }
/** {@inheritDoc} */ @Override protected JsonNode toJsonNode() { final ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(OPERATOR_NODE, mOperator.name()); final ArrayNode filters = root.arrayNode(); for (FijiRowFilter filter : mFilters) { if (filter != null) { filters.add(filter.toJson()); } } root.put(FILTERS_NODE, filters); return root; }
@Test public void testSessionInfoSending() { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); ObjectNode sessInfo = new ObjectNode(JsonNodeFactory.instance); sessInfo.put("type", "metaInfo"); sessInfo.put("browser", "Firefox"); sessInfo.put("device", "iOS"); sessInfo.put("language", "de"); beacon.put("sessionID", "" + Long.toString(SESSID_DEMOVALUE, 16)); beacon.put("tabID", "" + Long.toString(TABID_DEMOVALUE, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); data.add(sessInfo); String beaconJson = beacon.toString(); dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(1)).addDefaultData(any(DefaultData.class)); List<DefaultData> sent = sentElements.getAllValues(); assertThat(sent.size(), equalTo(1)); assertThat(sent.get(0), instanceOf(UserSessionInfo.class)); UserSessionInfo sentInfo = (UserSessionInfo) sent.get(0); assertThat(sentInfo.getBrowser(), equalTo("Firefox")); assertThat(sentInfo.getDevice(), equalTo("iOS")); assertThat(sentInfo.getLanguage(), equalTo("de")); assertThat(sentInfo.getSessionId(), equalTo(SESSID_DEMOVALUE)); }
ArrayNode array = to.arrayNode(); to.put("array", array); for (Object i : (Object[])from) { ArrayNode array = to.arrayNode(); to.put("_collection", array); for (Object o : obj) { else if (value instanceof String[]) { ArrayNode array = to.arrayNode(); to.put(name, array); for (String i : (String[])value) } else if (value instanceof Object[]) { ArrayNode array = to.arrayNode(); to.put(name, array); for (Object i : (Object[])value) { if (value instanceof Collection) { Collection<?> obj = (Collection<?>)value; ArrayNode array = to.arrayNode(); to.put(name, array); for (Object o : obj) {
@Test public void testInvalidBeaconContent() { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); ObjectNode sessInfo = new ObjectNode(JsonNodeFactory.instance); sessInfo.put("type", "unkownType"); sessInfo.put("browser", "Firefox"); sessInfo.put("device", "iOS"); sessInfo.put("language", "de"); beacon.put("sessionID", "" + Long.toString(SESSID_DEMOVALUE, 16)); beacon.put("tabID", "" + Long.toString(TABID_DEMOVALUE, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); data.add(sessInfo); String beaconJson = beacon.toString(); dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(0)).addDefaultData(any(DefaultData.class)); } }
@Override public WritableResourceNode<IConfig> createConfig(String key) throws MException { // find array node, to append new config if (node.get(key) != null && !node.get(key).isArray()) { node.remove(key); } ArrayNode array = (ArrayNode) node.get(key); if (array == null) { // if not, create one array = node.arrayNode(); node.put(key, array); } if (! (array instanceof ArrayNode) ) { throw new MException(key + " is not an array"); } // create new object node in array ObjectNode out = array.objectNode(); array.add(out); return new JsonConfig(key, this, out); }