use of com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.
the class RoaringBitmapJsonDeserialiser method deserialize.
@Override
public RoaringBitmap deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException {
final TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode bitmapObject = treeNode.get(RoaringBitmapConstants.BITMAP_WRAPPER_OBJECT_NAME);
if (bitmapObject != null) {
final TextNode jsonNodes = (TextNode) bitmapObject.get(RoaringBitmapConstants.BITMAP_VALUE_FIELD_NAME);
return (RoaringBitmap) bitmapSerialiser.deserialise(jsonNodes.binaryValue());
} else {
throw new IllegalArgumentException("Received null bitmap treenode");
}
}
use of com.fasterxml.jackson.databind.node.TextNode in project jackson-databind by FasterXML.
the class ArrayNodeTest method testDirectCreation.
public void testDirectCreation() throws IOException {
ArrayNode n = new ArrayNode(JsonNodeFactory.instance);
assertStandardEquals(n);
assertFalse(n.elements().hasNext());
assertFalse(n.fieldNames().hasNext());
TextNode text = TextNode.valueOf("x");
n.add(text);
assertEquals(1, n.size());
assertFalse(0 == n.hashCode());
assertTrue(n.elements().hasNext());
// no field names for arrays
assertFalse(n.fieldNames().hasNext());
// not used with arrays
assertNull(n.get("x"));
assertTrue(n.path("x").isMissingNode());
assertSame(text, n.get(0));
// single element, so:
assertFalse(n.has("field"));
assertFalse(n.hasNonNull("field"));
assertTrue(n.has(0));
assertTrue(n.hasNonNull(0));
assertFalse(n.has(1));
assertFalse(n.hasNonNull(1));
// add null node too
n.add((JsonNode) null);
assertEquals(2, n.size());
assertTrue(n.get(1).isNull());
assertTrue(n.has(1));
assertFalse(n.hasNonNull(1));
// change to text
n.set(1, text);
assertSame(text, n.get(1));
n.set(0, null);
assertTrue(n.get(0).isNull());
// and finally, clear it all
ArrayNode n2 = new ArrayNode(JsonNodeFactory.instance);
n2.add("foobar");
assertFalse(n.equals(n2));
n.addAll(n2);
assertEquals(3, n.size());
assertFalse(n.get(0).isTextual());
assertNotNull(n.remove(0));
assertEquals(2, n.size());
assertTrue(n.get(0).isTextual());
assertNull(n.remove(-1));
assertNull(n.remove(100));
assertEquals(2, n.size());
ArrayList<JsonNode> nodes = new ArrayList<JsonNode>();
nodes.add(text);
n.addAll(nodes);
assertEquals(3, n.size());
assertNull(n.get(10000));
assertNull(n.remove(-4));
TextNode text2 = TextNode.valueOf("b");
n.insert(0, text2);
assertEquals(4, n.size());
assertSame(text2, n.get(0));
assertNotNull(n.addArray());
assertEquals(5, n.size());
n.addPOJO("foo");
assertEquals(6, n.size());
// Try serializing it for fun, too...
JsonGenerator g = objectMapper().getFactory().createGenerator(new StringWriter());
n.serialize(g, null);
g.close();
n.removeAll();
assertEquals(0, n.size());
}
use of com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.
the class BidRequest method setup.
/**
* Sets up the database of values of the JSON, from the mapped keys in the
* campaigns. THis traverses the JSON once, and stores the required values
* needed by campaigns once.
*
* @throws Exception
* on JSON processing errors.
*/
protected void setup() throws Exception {
id = rootNode.path("id").textValue();
if (id == null) {
throw new Exception("Required field 'id' is missing or wrong type");
}
IntNode in = null;
Object test = null;
// a fast way to keep up
StringBuilder item = new StringBuilder("id");
// Im looking for
try {
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
List list = mapp.get(key);
if (list.size() != 0)
compileList(key, list);
}
// ////////////////////////////////////////////////////////////////////
if ((test = getNode("site.id")) != null)
siteId = ((TextNode) test).textValue();
else {
test = getNode("app.id");
if (test != null) {
siteId = ((TextNode) test).textValue();
}
}
if ((test = getNode("site.domain")) != null)
siteDomain = ((TextNode) test).textValue();
else {
test = getNode("app.domain");
if (test != null) {
siteDomain = ((TextNode) test).textValue();
}
}
// ///////////////
if (siteDomain != null && blackList != null) {
if (blackList.contains(siteDomain)) {
blackListed = true;
return;
}
}
if ((test = getNode("site.name")) != null)
siteName = ((TextNode) test).textValue();
else {
test = getNode("app.name");
if (test != null) {
siteName = ((TextNode) test).textValue();
}
}
////////////////// Fill in pageurl info ////////////////
if ((test = getNode("site.content.url")) != null) {
pageurl = ((TextNode) test).textValue();
} else if ((test = getNode("site.page")) != null) {
pageurl = ((TextNode) test).textValue();
} else {
test = getNode("app.content.url");
if (test != null) {
pageurl = ((TextNode) test).textValue();
}
}
if ((test = database.get("device.geo.lat")) != null && test instanceof MissingNode == false) {
try {
lat = getDoubleFrom(test);
test = database.get("device.geo.lon");
if (test != null)
lon = getDoubleFrom(test);
} catch (Exception error) {
}
}
//////////////////////////////////////////////////////////////////
//
// Handle the impressions
//
ArrayNode imps = (ArrayNode) rootNode.get("imp");
impressions = new ArrayList();
for (int i = 0; i < imps.size(); i++) {
JsonNode obj = imps.get(i);
Impression imp = new Impression(rootNode, obj);
impressions.add(imp);
}
handleRtb4FreeExtensions();
} catch (Exception error) {
// This is an error in the protocol
error.printStackTrace();
if (Configuration.isInitialized() == false)
return;
// error.printStackTrace();
// String str = rootNode.toString();
// System.out.println(str);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
error.printStackTrace(pw);
String str = sw.toString();
String[] lines = str.split("\n");
StringBuilder sb = new StringBuilder();
sb.append("Abmormal processing of bid ");
sb.append(id);
sb.append(", ");
if (lines.length > 0)
sb.append(lines[0]);
if (lines.length > 1)
sb.append(lines[1]);
Controller.getInstance().sendLog(4, "BidRequest:setup():error", sb.toString());
}
}
use of com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.
the class Node method traverse.
/**
* Traverse an ArrayNode and convert to ArrayList
*
* @param n.
* A Jackson ArrayNode.
* @return List. The list that corresponds to the Jackson ArrayNode.
*/
List traverse(ArrayNode n) {
List list = new ArrayList();
for (int i = 0; i < n.size(); i++) {
Object obj = n.get(i);
if (obj instanceof IntNode) {
IntNode d = (IntNode) obj;
list.add(d.numberValue());
} else if (obj instanceof DoubleNode) {
DoubleNode d = (DoubleNode) obj;
list.add(d.numberValue());
} else if (obj instanceof ArrayNode) {
ArrayNode nodes = (ArrayNode) obj;
for (int k = 0; i < nodes.size(); i++) {
list.add(nodes.get(k));
}
} else if (obj instanceof TextNode) {
TextNode t = (TextNode) obj;
list.add(t.textValue());
} else {
list.add(obj);
}
}
return list;
}
use of com.fasterxml.jackson.databind.node.TextNode in project XRTB by benmfaul.
the class ANode method traverse.
/**
* Traverse an ArrayNode and convert to ArrayList
*
* @param n. A Jackson ArrayNode.
* @return List. The list that corresponds to the Jackson ArrayNode.
*/
List traverse(ArrayNode n) {
List list = new ArrayList();
for (int i = 0; i < n.size(); i++) {
Object obj = n.get(i);
if (obj instanceof IntNode) {
IntNode d = (IntNode) obj;
list.add(d.numberValue());
} else if (obj instanceof DoubleNode) {
DoubleNode d = (DoubleNode) obj;
list.add(d.numberValue());
} else {
TextNode t = (TextNode) obj;
list.add(t.textValue());
}
}
return list;
}
Aggregations