本文整理汇总了Java中com.fasterxml.jackson.databind.node.TextNode类的典型用法代码示例。如果您正苦于以下问题:Java TextNode类的具体用法?Java TextNode怎么用?Java TextNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextNode类属于com.fasterxml.jackson.databind.node包,在下文中一共展示了TextNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
public Selector deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException {
ObjectMapper mapper = (ObjectMapper) p.getCodec();
ObjectNode obj = mapper.readTree(p);
String typeName;
if (obj.get("@type").isArray()) {
// Find the actual selector type
typeName = StreamSupport.stream(obj.get("@type").spliterator(), false)
.filter(v -> !v.textValue().equals("cnt:ContentAsText"))
.findFirst().orElse(new TextNode("UNKNOWN")).textValue();
// Make @type a text value so that Jackson doesn't bail out further down the line
obj.set("@type", new TextNode(typeName));
} else {
typeName = obj.get("@type").textValue();
}
if (MAPPING.containsKey(typeName)) {
return mapper.treeToValue(obj, MAPPING.get(typeName));
} else {
throw new IllegalArgumentException("Cannot deserialize Selector.");
}
}
示例2: applyGeneratesDate
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test
public void applyGeneratesDate() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "string");
TextNode formatNode = TextNode.valueOf("date-time");
objectNode.set("format", formatNode);
JType mockDateType = mock(JType.class);
FormatRule mockFormatRule = mock(FormatRule.class);
when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), Mockito.isA(JType.class), isNull(Schema.class))).thenReturn(mockDateType);
when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);
JType result = rule.apply("fooBar", objectNode, jpackage, null);
assertThat(result, equalTo(mockDateType));
}
示例3: getComponentMeta
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
private ObjectNode getComponentMeta(ClassLoader classLoader) {
Properties properties = loadComponentProperties(classLoader);
if (properties == null) {
return null;
}
String components = (String) properties.get("components");
if (components == null) {
return null;
}
String[] part = components.split("\\s");
ObjectNode componentMeta = new ObjectNode(JsonNodeFactory.instance);
for (String scheme : part) {
// find the class name
String javaType = extractComponentJavaType(classLoader, scheme);
if (javaType == null) {
continue;
}
String schemeMeta = loadComponentJSonSchema(classLoader, scheme, javaType);
if (schemeMeta == null) {
continue;
}
componentMeta.set(scheme, new TextNode(schemeMeta));
}
return componentMeta.size() > 0 ? componentMeta : null;
}
示例4: get
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
public static JsonNode get( final PrimitiveObject obj ) throws IOException{
switch( obj.getPrimitiveType() ){
case BOOLEAN:
return BooleanNode.valueOf( obj.getBoolean() );
case BYTE:
return IntNode.valueOf( obj.getInt() );
case SHORT:
return IntNode.valueOf( obj.getInt() );
case INTEGER:
return IntNode.valueOf( obj.getInt() );
case LONG:
return new LongNode( obj.getLong() );
case FLOAT:
return new DoubleNode( obj.getDouble() );
case DOUBLE:
return new DoubleNode( obj.getDouble() );
case STRING:
return new TextNode( obj.getString() );
case BYTES:
return new BinaryNode( obj.getBytes() );
default:
return new TextNode( null );
}
}
示例5: testMappingException
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test(expected = WebApplicationException.class)
public void testMappingException() throws Exception {
final ObjectMapper om = mock(ObjectMapper.class);
when(om.writeValueAsString(any())).thenThrow(new JsonProcessingException("ignore me") {
private static final long serialVersionUID = 1L;
@Override
public StackTraceElement[] getStackTrace() {
return new StackTraceElement[] {};
}
});
uut = new FactsTransactionsResource(mock(FactStore.class), om);
final FactTransactionJson tx = new FactTransactionJson();
tx.facts(Arrays.asList(new FactJson().payload(TextNode.valueOf("buh"))));
uut.newTransaction(tx);
}
示例6: activate
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Activate
public void activate() {
Serializer serializer = Serializer.using(KryoNamespaces.API,
ObjectNode.class, ArrayNode.class,
JsonNodeFactory.class, LinkedHashMap.class,
TextNode.class, BooleanNode.class,
LongNode.class, DoubleNode.class, ShortNode.class,
IntNode.class, NullNode.class);
prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder()
.withName(ONOS_USER_PREFERENCES)
.withSerializer(serializer)
.withRelaxedReadConsistency()
.build();
prefsConsistentMap.addListener(prefsListener);
prefs = prefsConsistentMap.asJavaMap();
register(core);
log.info("Started");
}
示例7: activate
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Activate
public void activate() {
KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder()
.register(KryoNamespaces.API)
.register(ConfigKey.class, ObjectNode.class, ArrayNode.class,
JsonNodeFactory.class, LinkedHashMap.class,
TextNode.class, BooleanNode.class,
LongNode.class, DoubleNode.class, ShortNode.class, IntNode.class,
NullNode.class);
configs = storageService.<ConfigKey, JsonNode>consistentMapBuilder()
.withSerializer(Serializer.using(kryoBuilder.build()))
.withName("onos-network-configs")
.withRelaxedReadConsistency()
.build();
configs.addListener(listener);
log.info("Started");
}
示例8: getDetails
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
/**
* Gets the details of an input or output
* @param inputOutput The node of the particular input or output
* @return An CWLElement object with the label, doc and type extracted
*/
private CWLElement getDetails(JsonNode inputOutput) {
if (inputOutput != null) {
CWLElement details = new CWLElement();
// Shorthand notation "id: type" - no label/doc/other params
if (inputOutput.getClass() == TextNode.class) {
details.setType(inputOutput.asText());
} else {
details.setLabel(extractLabel(inputOutput));
details.setDoc(extractDoc(inputOutput));
extractSource(inputOutput).forEach(details::addSourceID);
details.setDefaultVal(extractDefault(inputOutput));
// Type is only for inputs
if (inputOutput.has(TYPE)) {
details.setType(extractTypes(inputOutput.get(TYPE)));
}
}
return details;
}
return null;
}
示例9: map
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
/**
* Map existing JsonRpcRequest to Jackson JsonNode.
*
* @param request the JsonRpcRequest
* @return the ObjectNode
*/
public static ObjectNode map(JsonRpcRequest request) {
if (request == null) {
return null;
}
ObjectNode node = new ObjectNode(JsonNodeFactory.instance);
// Set protocol version
node.set("jsonrpc", JSON_RPC_VERSION);
// Set method
node.set("method", new TextNode(request.getMethod()));
// Set id
if (request.getId() != null) {
node.set("id", new TextNode(request.getId()));
}
// Set Params
Map<String, String> params = request.getParams();
if (params != null && !params.isEmpty()) {
ObjectMapper mapper = new ObjectMapper();
node.set("params", mapper.valueToTree(params));
}
return node;
}
示例10: shouldUpdateNameSuccessfully
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test
public void shouldUpdateNameSuccessfully() throws Exception {
String serviceId = randomUuid();
String nameToUpdate = "new-name";
ServiceUpdateRequest request = ServiceUpdateRequest.from(new ObjectNode(JsonNodeFactory.instance, ImmutableMap.of(
"path", new TextNode("name"),
"value", new TextNode(nameToUpdate),
"op", new TextNode("replace"))));
ServiceEntity serviceEntity = mock(ServiceEntity.class);
when(serviceDao.findByExternalId(serviceId)).thenReturn(Optional.of(serviceEntity));
when(serviceEntity.toService()).thenReturn(Service.from());
Optional<Service> maybeService = updater.doUpdate(serviceId, request);
assertThat(maybeService.isPresent(), is(true));
verify(serviceEntity, times(1)).setName(nameToUpdate);
verify(serviceDao, times(1)).merge(serviceEntity);
}
示例11: testEntityCreationSuccess
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test
public void testEntityCreationSuccess() {
String collectionName = "ect" + System.currentTimeMillis();
String entityName = "testEntity1";
HashMap<String,JsonNode> map = new HashMap<>();
map.put("name",new TextNode(entityName));
map.put("color",new TextNode("red"));
map.put("shape",new TextNode("square"));
UsergridEntity entity = new UsergridEntity(collectionName,null,map);
UsergridResponse response = entity.save();
assertNull(response.getResponseError());
UsergridEntity eLookUp = Usergrid.GET(collectionName, entityName).first();
assertNotNull("The returned entity is null!", eLookUp);
assertEquals("entities has the correct type", eLookUp.getType(),collectionName);
assertEquals("entities has the correct name", eLookUp.getName(),entityName);
assertEquals("entities has the correct color", eLookUp.getStringProperty("color"),"red");
assertEquals("entities has the correct shape", eLookUp.getStringProperty("shape"),"square");
}
示例12: deserialize
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Override
public GoalState deserialize(
JsonParser p, DeserializationContext ctxt) throws IOException, JsonParseException {
String value = ((TextNode) p.getCodec().readTree(p)).textValue();
if (value.equals("FINISHED") || value.equals("ONCE")) {
return referenceTerminalGoalState;
} else if (value.equals("FINISH")) {
return GoalState.FINISH;
} else if (value.equals("RUNNING")) {
return GoalState.RUNNING;
} else {
logger.warn("Found unknown goal state in config store: {}", value);
return GoalState.UNKNOWN;
}
}
示例13: getSharedDevice
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@NotNull
public static UsergridDevice getSharedDevice(@NotNull final Context context) {
if (sharedDevice == null) {
sharedDevice = UsergridSharedDevice.getStoredSharedDevice(context);
if (sharedDevice == null) {
String sharedDeviceId = UsergridSharedDevice.getSharedDeviceUUID(context);
HashMap<String, JsonNode> map = new HashMap<String, JsonNode>();
map.put("uuid", new TextNode(sharedDeviceId));
sharedDevice = new UsergridDevice(map);
sharedDevice.setModel(Build.MODEL);
sharedDevice.setPlatform("android");
sharedDevice.setOsVersion(Build.VERSION.RELEASE);
}
}
return sharedDevice;
}
示例14: deserialize
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test
public void deserialize() throws Exception {
StratumMessage m1 = readValue("{\"id\":123, \"method\":\"a.b\", \"params\":[1, \"x\", null]}");
assertEquals(123L, (long)m1.id);
assertEquals("a.b", m1.method);
assertEquals(Lists.newArrayList(new IntNode(1), new TextNode("x"), NullNode.getInstance()), m1.params);
StratumMessage m2 = readValue("{\"id\":123, \"result\":{\"x\": 123}}");
assertTrue(m2.isResult());
assertEquals(123L, (long)m2.id);
assertEquals(mapper.createObjectNode().put("x", 123), m2.result);
StratumMessage m3 = readValue("{\"id\":123, \"result\":[\"x\"]}");
assertEquals(123L, (long)m3.id);
//noinspection AssertEqualsBetweenInconvertibleTypes
assertEquals(mapper.createArrayNode().add("x"), m3.result);
}
示例15: createActitvityExtract
import com.fasterxml.jackson.databind.node.TextNode; //导入依赖的package包/类
@Test
public void createActitvityExtract() throws Exception
{
MarketoResponse<ObjectNode> marketoResponse = new MarketoResponse<>();
marketoResponse.setSuccess(true);
Date startDate = new Date(1506865856000L);
Date endDate = new Date(1507297856000L);
ObjectNode bulkExtractResult = OBJECT_MAPPER.createObjectNode();
bulkExtractResult.set("exportId", new TextNode("bulkExtractId"));
marketoResponse.setResult(Arrays.asList(bulkExtractResult));
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
Mockito.doReturn(marketoResponse).when(marketoRestClient).doPost(Mockito.eq(END_POINT + MarketoRESTEndpoint.CREATE_ACTIVITY_EXTRACT.getEndpoint()), Mockito.isNull(Map.class), Mockito.isNull(ImmutableListMultimap.class), argumentCaptor.capture(), Mockito.any(MarketoResponseJetty92EntityReader.class));
String bulkExtractId = marketoRestClient.createActivityExtract(startDate, endDate);
Assert.assertEquals("bulkExtractId", bulkExtractId);
String postContent = argumentCaptor.getValue();
ObjectNode marketoBulkExtractRequest = (ObjectNode) OBJECT_MAPPER.readTree(postContent);
ObjectNode filter = (ObjectNode) marketoBulkExtractRequest.get("filter");
Assert.assertTrue(filter.has("createdAt"));
}