List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.redhat.lightblue.crud.validator.StringLengthCheckerTest.java
@Test public void testCheckConstraint_MINLENGTH() { ConstraintValidator validator = mock(ConstraintValidator.class); StringLengthConstraint constraint = new StringLengthConstraint(StringLengthConstraint.MINLENGTH, 5); JsonNode fieldValue = mock(JsonNode.class); when(fieldValue.asText()).thenReturn("12345"); new StringLengthChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }
From source file:com.redhat.lightblue.crud.validator.StringLengthCheckerTest.java
@Test public void testCheckConstraint_MAXLENGTH() { ConstraintValidator validator = mock(ConstraintValidator.class); StringLengthConstraint constraint = new StringLengthConstraint("fake type", 5); JsonNode fieldValue = mock(JsonNode.class); when(fieldValue.asText()).thenReturn("12345"); new StringLengthChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, never()).addDocError(any(Error.class)); }
From source file:com.redhat.lightblue.crud.validator.StringLengthCheckerTest.java
@Test public void testCheckConstraint_MINLENGTH_TooShort() { ConstraintValidator validator = mock(ConstraintValidator.class); StringLengthConstraint constraint = new StringLengthConstraint(StringLengthConstraint.MINLENGTH, 5); JsonNode fieldValue = mock(JsonNode.class); when(fieldValue.asText()).thenReturn("1234"); new StringLengthChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
From source file:com.redhat.lightblue.crud.validator.StringLengthCheckerTest.java
@Test public void testCheckConstraint_MAXLENGTH_TooLong() { ConstraintValidator validator = mock(ConstraintValidator.class); StringLengthConstraint constraint = new StringLengthConstraint("fake type", 5); JsonNode fieldValue = mock(JsonNode.class); when(fieldValue.asText()).thenReturn("123456"); new StringLengthChecker().checkConstraint(validator, null, null, constraint, null, null, fieldValue); verify(validator, times(1)).addDocError(any(Error.class)); }
From source file:br.com.itw.commons.json.JsonDateDeserializer.java
@Override public Date deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); try {// w w w. j a va 2s.c o m return (Date) dateFormat.parse(node.asText()); } catch (ParseException e) { try { return (Date) dateFormat2.parse(node.asText()); } catch (ParseException e1) { throw new IOException(e); } } }
From source file:com.github.sakserv.storm.scheme.HumiditySensorJsonScheme.java
@Override public List<Object> deserialize(byte[] bytes) { int deviceId = 0; int humidity = 0; int temperature = 0; String dt = null;/*from w w w .j a va2 s. com*/ try { // Convert to string and read as json tree String eventDetails = new String(bytes, "UTF-8"); JsonNode rootNode = mapper.readTree(eventDetails); // Get the deviceId JsonNode deviceIdNode = rootNode.path("deviceid"); deviceId = deviceIdNode.asInt(); // Get the humidity JsonNode humidityNode = rootNode.path("humidity"); humidity = humidityNode.asInt(); // Get the temperature JsonNode temperatureNode = rootNode.path("temperature"); temperature = temperatureNode.asInt(); // Get the dt JsonNode dtNode = rootNode.path("dt"); dt = dtNode.asText(); return new Values(deviceId, humidity, temperature, dt); } catch (IOException e) { e.printStackTrace(); } return new Values(deviceId, humidity, temperature, dt); }
From source file:com.ikanow.aleph2.graph.titan.utils.TitanGraphBuildingUtils.java
/** Inserts a single-valued vertex property into a JSON object * @param f//from w w w .j a v a2 s. c om * @param vp * @param o * @return */ protected static Object jsonNodeToObject(final JsonNode j) { return Patterns.match().<Object>andReturn().when(() -> null == j, () -> j) .when(() -> j.isTextual(), () -> j.asText()).when(() -> j.isDouble(), () -> j.asDouble()) .when(() -> j.isIntegralNumber(), () -> j.asLong()).when(() -> j.isBoolean(), () -> j.asBoolean()) .otherwise(__ -> null); }
From source file:de.fraunhofer.iosb.ilt.sta.deserialize.TimeValueDeserializer.java
@Override public TimeValue deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JsonProcessingException { TimeValue result;//from w ww . ja v a 2s. c o m JsonNode node = jp.getCodec().readTree(jp); try { result = TimeInstant.parse(node.asText()); } catch (Exception e) { result = TimeInterval.parse(node.asText()); } return result; }
From source file:com.aol.one.patch.testobj.PatchTestObject.java
public void replaceStrField(JsonNode node) { this.strField = node.asText(); }
From source file:com.reprezen.swagedit.assist.ext.MediaTypeContentAssistExt.java
@Override public Collection<Proposal> getProposals(TypeDefinition type, AbstractNode node, String prefix) { Collection<Proposal> proposals = new ArrayList<>(); prefix = Strings.emptyToNull(prefix); for (JsonNode mediaType : mediaTypes) { String asText = mediaType.asText(); if (prefix != null) { if (asText.contains(prefix.trim())) { proposals.add(createProposal(type, mediaType)); }//from w ww . j a va2 s . c o m } else { proposals.add(createProposal(type, mediaType)); } } return proposals; }