Here are the examples of the java api class com.fasterxml.jackson.databind.node.ObjectNode taken from open source projects.
1. GenericRESTTemplateService#getActivityConfiguration()
Project: incubator-taverna-workbench-common-activities
File: GenericRESTTemplateService.java
File: GenericRESTTemplateService.java
@Override public Configuration getActivityConfiguration() { Configuration configuration = new Configuration(); configuration.setType(ACTIVITY_TYPE.resolve("#Config")); ObjectNode json = (ObjectNode) configuration.getJson(); ObjectNode requestNode = json.objectNode(); requestNode.put("httpMethod", RESTActivity.HTTP_METHOD.GET.name()); requestNode.put("absoluteURITemplate", "http://www.uniprot.org/uniprot/{id}.xml"); ArrayNode headersNode = requestNode.arrayNode(); headersNode.addObject().put("header", "Accept").put("value", "application/xml"); headersNode.addObject().put("header", "Content-Type").put("value", "application/xml"); requestNode.set("headers", headersNode); json.set("request", requestNode); json.put("outgoingDataFormat", RESTActivity.DATA_FORMAT.String.name()); json.put("showRedirectionOutputPort", false); json.put("showActualURLPort", false); json.put("showResponseHeadersPort", false); json.put("escapeParameters", true); return configuration; }
2. OnosSwaggerMojo#initializeRoot()
Project: onos
File: OnosSwaggerMojo.java
File: OnosSwaggerMojo.java
// initializes top level root with Swagger required specifications private ObjectNode initializeRoot() { ObjectNode root = mapper.createObjectNode(); root.put("swagger", "2.0"); ObjectNode info = mapper.createObjectNode(); root.set("info", info); root.put("basePath", webContext); info.put("version", apiVersion); info.put("title", apiTitle); info.put("description", apiDescription); ArrayNode produces = mapper.createArrayNode(); produces.add("application/json"); root.set("produces", produces); ArrayNode consumes = mapper.createArrayNode(); consumes.add("application/json"); root.set("consumes", consumes); return root; }
3. SpreadsheetImportTemplateService#getActivityConfiguration()
Project: incubator-taverna-workbench-common-activities
File: SpreadsheetImportTemplateService.java
File: SpreadsheetImportTemplateService.java
@Override public Configuration getActivityConfiguration() { Configuration configuration = new Configuration(); configuration.setType(ACTIVITY_TYPE.resolve("#Config")); ObjectNode json = (ObjectNode) configuration.getJson(); json.put("columnRange", json.objectNode().put("start", 0).put("end", 1)); json.put("rowRange", json.objectNode().put("start", 0).put("end", -1)); json.put("emptyCellValue", ""); json.put("allRows", true); json.put("excludeFirstRow", false); json.put("ignoreBlankRows", false); json.put("emptyCellPolicy", "EMPTY_STRING"); json.put("outputFormat", "PORT_PER_COLUMN"); json.put("csvDelimiter", ","); return configuration; }
4. SpreadsheetImportHealthCheckerTest#testCheckHealth()
Project: incubator-taverna-common-activities
File: SpreadsheetImportHealthCheckerTest.java
File: SpreadsheetImportHealthCheckerTest.java
/** * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportHealthChecker#checkHealth(net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportActivity)}. * @throws Exception */ @Test public void testCheckHealth() throws Exception { assertEquals(Status.SEVERE, healthChecker.visit(activity, ancestors).getStatus()); ObjectNode configuration = JsonNodeFactory.instance.objectNode(); configuration.put("columnRange", configuration.objectNode().put("start", 0).put("end", 1)); configuration.put("rowRange", configuration.objectNode().put("start", 0).put("end", -1)); configuration.put("emptyCellValue", ""); configuration.put("allRows", true); configuration.put("excludeFirstRow", false); configuration.put("ignoreBlankRows", false); configuration.put("emptyCellPolicy", "EMPTY_STRING"); configuration.put("outputFormat", "PORT_PER_COLUMN"); configuration.put("csvDelimiter", ","); activity.configure(configuration); assertEquals(Status.OK, healthChecker.visit(activity, ancestors).getStatus()); }
5. ElasticsearchClient#getDashboardForElasticsearch()
Project: stagemonitor
File: ElasticsearchClient.java
File: ElasticsearchClient.java
ObjectNode getDashboardForElasticsearch(String dashboardPath) throws IOException { final ObjectMapper mapper = JsonUtils.getMapper(); final ObjectNode dashboard = (ObjectNode) mapper.readTree(IOUtils.getResourceAsStream(dashboardPath)); dashboard.put("editable", false); ObjectNode dashboardElasticsearchFormat = mapper.createObjectNode(); dashboardElasticsearchFormat.put("user", "guest"); dashboardElasticsearchFormat.put("group", "guest"); dashboardElasticsearchFormat.set(TITLE, dashboard.get(TITLE)); dashboardElasticsearchFormat.set("tags", dashboard.get("tags")); dashboardElasticsearchFormat.put("dashboard", dashboard.toString()); return dashboardElasticsearchFormat; }
6. BgpRoutesListCommand#json()
Project: onos
File: BgpRoutesListCommand.java
File: BgpRoutesListCommand.java
/** * Produces JSON object for a route. * * @param mapper the JSON object mapper to use * @param route the route with the data * @return JSON object for the route */ private ObjectNode json(ObjectMapper mapper, BgpRouteEntry route) { ObjectNode result = mapper.createObjectNode(); result.put("prefix", route.prefix().toString()); result.put("nextHop", route.nextHop().toString()); result.put("bgpId", route.getBgpSession().remoteInfo().bgpId().toString()); result.put("origin", BgpConstants.Update.Origin.typeToString(route.getOrigin())); result.set("asPath", json(mapper, route.getAsPath())); result.put("localPref", route.getLocalPref()); result.put("multiExitDisc", route.getMultiExitDisc()); return result; }
7. OnosSwaggerMojo#addResponses()
Project: onos
File: OnosSwaggerMojo.java
File: OnosSwaggerMojo.java
// Temporary solution to add responses to a method private void addResponses(ObjectNode methodNode, DocletTag tag, boolean responseJson) { ObjectNode responses = mapper.createObjectNode(); methodNode.set("responses", responses); ObjectNode success = mapper.createObjectNode(); success.put("description", "successful operation"); responses.set("200", success); if (tag != null && responseJson) { ObjectNode schema = mapper.createObjectNode(); tag.getParameters().stream().forEach( param -> schema.put("$ref", "#/definitions/" + param)); success.set("schema", schema); } ObjectNode defaultObj = mapper.createObjectNode(); defaultObj.put("description", "Unexpected error"); responses.set("default", defaultObj); }
8. PluginInternalPreferences#toString()
Project: cordova-hot-code-push
File: PluginInternalPreferences.java
File: PluginInternalPreferences.java
/** * Convert object into JSON string * * @return JSON string */ @Override public String toString() { JsonNodeFactory nodeFactory = JsonNodeFactory.instance; ObjectNode object = nodeFactory.objectNode(); object.set(APPLICATION_BUILD_VERSION, nodeFactory.numberNode(appBuildVersion)); object.set(WWW_FOLDER_INSTALLED_FLAG, nodeFactory.booleanNode(wwwFolderInstalled)); object.set(CURRENT_RELEASE_VERSION_NAME, nodeFactory.textNode(currentReleaseVersionName)); object.set(PREVIOUS_RELEASE_VERSION_NAME, nodeFactory.textNode(previousReleaseVersionName)); object.set(READY_FOR_INSTALLATION_RELEASE_VERSION_NAME, nodeFactory.textNode(readyForInstallationReleaseVersionName)); return object.toString(); }
9. ESAggregateVisitor#visitGroupBy()
Project: lens
File: ESAggregateVisitor.java
File: ESAggregateVisitor.java
@Override public void visitGroupBy(String groupBy) { groupBy = visitColumn(groupBy); final ObjectNode aggNode = JSON_NODE_FACTORY.objectNode(); currentGroupByNode.put(ESDriverConfig.AGGS, aggNode); final ObjectNode groupByNode = JSON_NODE_FACTORY.objectNode(); aggNode.put(Validate.notNull(groupByKeys.get(groupBy), "Group by column has to be used in select"), groupByNode); final ObjectNode termsNode = JSON_NODE_FACTORY.objectNode(); groupByNode.put(ESDriverConfig.TERMS, termsNode); termsNode.put(ESDriverConfig.FIELD, groupBy); termsNode.put(ESDriverConfig.SIZE, config.getAggrBucketSize()); currentGroupByNode = groupByNode; }
10. BpmResource#getProcessDefinitionResponse()
Project: lemon
File: BpmResource.java
File: BpmResource.java
private JsonNode getProcessDefinitionResponse(ProcessDefinitionEntity processDefinition) { ObjectMapper mapper = new ObjectMapper(); ObjectNode pdrJSON = mapper.createObjectNode(); pdrJSON.put("id", processDefinition.getId()); pdrJSON.put("name", processDefinition.getName()); pdrJSON.put("key", processDefinition.getKey()); pdrJSON.put("version", processDefinition.getVersion()); pdrJSON.put("deploymentId", processDefinition.getDeploymentId()); pdrJSON.put("isGraphicNotationDefined", isGraphicNotationDefined(processDefinition)); return pdrJSON; }
11. JsonRpcBasicServer#createResponseError()
Project: jsonrpc4j
File: JsonRpcBasicServer.java
File: JsonRpcBasicServer.java
/** * Convenience method for creating an error response. * * @param jsonRpc the jsonrpc string * @param id the id * @param errorObject the error data (if any) * @return the error response */ private ErrorObjectWithJsonError createResponseError(String jsonRpc, Object id, JsonError errorObject) { ObjectNode response = mapper.createObjectNode(); ObjectNode error = mapper.createObjectNode(); error.put(ERROR_CODE, errorObject.code); error.put(ERROR_MESSAGE, errorObject.message); if (errorObject.data != null) { error.set(DATA, mapper.valueToTree(errorObject.data)); } response.put(JSONRPC, jsonRpc); if (Integer.class.isInstance(id)) { response.put(ID, Integer.class.cast(id).intValue()); } else if (Long.class.isInstance(id)) { response.put(ID, Long.class.cast(id).longValue()); } else if (Float.class.isInstance(id)) { response.put(ID, Float.class.cast(id).floatValue()); } else if (Double.class.isInstance(id)) { response.put(ID, Double.class.cast(id).doubleValue()); } else if (BigDecimal.class.isInstance(id)) { response.put(ID, BigDecimal.class.cast(id)); } else { response.put(ID, String.class.cast(id)); } response.set(ERROR, error); return new ErrorObjectWithJsonError(response, errorObject); }
12. Neo4jHttpGraphHelper#createHttpRequest()
Project: incubator-streams
File: Neo4jHttpGraphHelper.java
File: Neo4jHttpGraphHelper.java
public ObjectNode createHttpRequest(Pair<String, Map<String, Object>> queryPlusParameters) { LOGGER.debug("createHttpRequest: ", queryPlusParameters); Preconditions.checkNotNull(queryPlusParameters); Preconditions.checkNotNull(queryPlusParameters.getValue0()); Preconditions.checkNotNull(queryPlusParameters.getValue1()); ObjectNode request = MAPPER.createObjectNode(); request.put(statementKey, queryPlusParameters.getValue0()); ObjectNode params = MAPPER.createObjectNode(); ObjectNode props = MAPPER.convertValue(queryPlusParameters.getValue1(), ObjectNode.class); params.put(propsKey, props); request.put(paramsKey, params); LOGGER.debug("createHttpRequest: ", request); return request; }
13. SimpleElasticsearchReporter#report()
Project: stagemonitor
File: SimpleElasticsearchReporter.java
File: SimpleElasticsearchReporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final ObjectMapper mapper = JsonUtils.getMapper(); final ObjectNode jsonReport = mapper.valueToTree(Stagemonitor.getMeasurementSession()); jsonReport.set("gauges", mapper.valueToTree(gauges)); jsonReport.set("counters", mapper.valueToTree(counters)); jsonReport.set("histograms", mapper.valueToTree(histograms)); jsonReport.set("meters", mapper.valueToTree(meters)); jsonReport.set("timers", mapper.valueToTree(timers)); elasticsearchClient.sendAsJson("POST", "/stagemonitor/measurementSessions", jsonReport); }
14. ThresholdMonitoringReporter#report()
Project: stagemonitor
File: ThresholdMonitoringReporter.java
File: ThresholdMonitoringReporter.java
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { ObjectNode metrics = JsonUtils.getMapper().createObjectNode(); metrics.set(MetricCategory.GAUGE.getPath(), JsonUtils.toObjectNode(gauges)); metrics.set(MetricCategory.COUNTER.getPath(), JsonUtils.toObjectNode(counters)); metrics.set(MetricCategory.HISTOGRAM.getPath(), JsonUtils.toObjectNode(histograms)); metrics.set(MetricCategory.METER.getPath(), JsonUtils.toObjectNode(meters)); metrics.set(MetricCategory.TIMER.getPath(), JsonUtils.toObjectNode(timers)); for (Check check : alertingPlugin.getChecks().values()) { if (measurementSession.getApplicationName().equals(check.getApplication()) && check.isActive()) { checkMetrics(metrics, check); } } }
15. JSONUtilities#addOperation()
Project: olingo-odata4
File: JSONUtilities.java
File: JSONUtilities.java
@Override public InputStream addOperation(final InputStream content, final String name, final String metaAnchor, final String href) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(content); IOUtils.closeQuietly(content); final ObjectNode action = mapper.createObjectNode(); action.set("title", new TextNode(name)); action.set("target", new TextNode(href)); srcNode.set(metaAnchor, action); return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); }
16. ArrayRuleTest#arrayDefaultsToNonUnique()
Project: jsonschema2pojo
File: ArrayRuleTest.java
File: ArrayRuleTest.java
@Test public void arrayDefaultsToNonUnique() { JCodeModel codeModel = new JCodeModel(); JPackage jpackage = codeModel._package(getClass().getPackage().getName()); ObjectMapper mapper = new ObjectMapper(); ObjectNode itemsNode = mapper.createObjectNode(); itemsNode.put("type", "boolean"); ObjectNode propertyNode = mapper.createObjectNode(); propertyNode.put("uniqueItems", false); propertyNode.put("items", itemsNode); Schema schema = mock(Schema.class); when(schema.getId()).thenReturn(URI.create("http://example/defaultArray")); JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema); assertThat(propertyType.erasure(), is(codeModel.ref(List.class))); }
17. ArrayRuleTest#arrayOfPrimitivesProducesCollectionOfWrapperTypes()
Project: jsonschema2pojo
File: ArrayRuleTest.java
File: ArrayRuleTest.java
@Test public void arrayOfPrimitivesProducesCollectionOfWrapperTypes() { JCodeModel codeModel = new JCodeModel(); JPackage jpackage = codeModel._package(getClass().getPackage().getName()); ObjectMapper mapper = new ObjectMapper(); ObjectNode itemsNode = mapper.createObjectNode(); itemsNode.put("type", "number"); ObjectNode propertyNode = mapper.createObjectNode(); propertyNode.put("uniqueItems", false); propertyNode.put("items", itemsNode); Schema schema = mock(Schema.class); when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray")); when(config.isUsePrimitives()).thenReturn(true); when(config.isUseDoubleNumbers()).thenReturn(true); JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema); assertThat(propertyType, notNullValue()); assertThat(propertyType.erasure(), is(codeModel.ref(List.class))); assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName())); }
18. ArrayRuleTest#arrayWithNonUniqueItemsProducesList()
Project: jsonschema2pojo
File: ArrayRuleTest.java
File: ArrayRuleTest.java
@Test public void arrayWithNonUniqueItemsProducesList() { JCodeModel codeModel = new JCodeModel(); JPackage jpackage = codeModel._package(getClass().getPackage().getName()); ObjectMapper mapper = new ObjectMapper(); ObjectNode itemsNode = mapper.createObjectNode(); itemsNode.put("type", "number"); ObjectNode propertyNode = mapper.createObjectNode(); propertyNode.put("uniqueItems", false); propertyNode.put("items", itemsNode); Schema schema = mock(Schema.class); when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray")); when(config.isUseDoubleNumbers()).thenReturn(true); JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema); assertThat(propertyType, notNullValue()); assertThat(propertyType.erasure(), is(codeModel.ref(List.class))); assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName())); }
19. ArrayRuleTest#arrayWithUniqueItemsProducesSet()
Project: jsonschema2pojo
File: ArrayRuleTest.java
File: ArrayRuleTest.java
@Test public void arrayWithUniqueItemsProducesSet() { JCodeModel codeModel = new JCodeModel(); JPackage jpackage = codeModel._package(getClass().getPackage().getName()); ObjectMapper mapper = new ObjectMapper(); ObjectNode itemsNode = mapper.createObjectNode(); itemsNode.put("type", "integer"); ObjectNode propertyNode = mapper.createObjectNode(); propertyNode.put("uniqueItems", true); propertyNode.put("items", itemsNode); JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, mock(Schema.class)); assertThat(propertyType, notNullValue()); assertThat(propertyType.erasure(), is(codeModel.ref(Set.class))); assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Integer.class.getName())); }
20. JacksonJsonNodeJsonProviderTest#always_return_same_object()
Project: JsonPath
File: JacksonJsonNodeJsonProviderTest.java
File: JacksonJsonNodeJsonProviderTest.java
@Test public void always_return_same_object() { // Test because of Bug #211 DocumentContext context = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT); ObjectNode node1 = context.read("$"); ObjectNode child1 = new ObjectNode(JsonNodeFactory.instance); child1.put("name", "test"); context.put("$", "child", child1); ObjectNode node2 = context.read("$"); ObjectNode child2 = context.read("$.child"); assertThat(node1).isSameAs(node2); assertThat(child1).isSameAs(child2); }
21. TestWSDLActivityContextualView#setUp()
Project: incubator-taverna-workbench-common-activities
File: TestWSDLActivityContextualView.java
File: TestWSDLActivityContextualView.java
@Before public void setUp() throws Exception { a = new Activity(); Configuration configuration = new Configuration(); ObjectNode json = (ObjectNode) configuration.getJson(); ObjectNode operation = json.objectNode(); operation.put("name", "getReport"); json.set("operation", operation); String wsdlUrl = TestWSDLActivityContextualView.class.getResource("/GMService.wsdl").toExternalForm(); operation.put("wsdl", wsdlUrl); configuration.setConfigures(a); }
22. PointToPointIntentCodec#encode()
Project: onos
File: PointToPointIntentCodec.java
File: PointToPointIntentCodec.java
@Override public ObjectNode encode(PointToPointIntent intent, CodecContext context) { checkNotNull(intent, "Point to point intent cannot be null"); final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class); final ObjectNode result = connectivityIntentCodec.encode(intent, context); final JsonCodec<ConnectPoint> connectPointCodec = context.codec(ConnectPoint.class); final ObjectNode ingress = connectPointCodec.encode(intent.ingressPoint(), context); final ObjectNode egress = connectPointCodec.encode(intent.egressPoint(), context); result.set(INGRESS_POINT, ingress); result.set(EGRESS_POINT, egress); return result; }
23. TopoJson#json()
Project: onos
File: TopoJson.java
File: TopoJson.java
/** * Translates the given property panel into JSON, for returning * to the client. * * @param pp the property panel model * @return JSON payload */ public static ObjectNode json(PropertyPanel pp) { ObjectNode result = objectNode().put(TITLE, pp.title()).put(TYPE, pp.typeId()).put(ID, pp.id()); ObjectNode pnode = objectNode(); ArrayNode porder = arrayNode(); for (PropertyPanel.Prop p : pp.properties()) { porder.add(p.key()); pnode.put(p.key(), p.value()); } result.set(PROP_ORDER, porder); result.set(PROPS, pnode); ArrayNode buttons = arrayNode(); for (ButtonId b : pp.buttons()) { buttons.add(b.id()); } result.set(BUTTONS, buttons); return result; }
24. CordModelCache#jsonDashboard()
Project: onos
File: CordModelCache.java
File: CordModelCache.java
/** * Returns the dashboard page data as JSON. * * @return dashboard page JSON data */ public synchronized String jsonDashboard() { log.info("jsonDashboard()"); if (email == null) { return jsonLogout(); } BundleDescriptor bundleDescriptor = currentBundle.descriptor(); ObjectNode root = objectNode(); root.put(BUNDLE_NAME, bundleDescriptor.displayName()); root.put(BUNDLE_DESC, bundleDescriptor.description()); root.set(USERS, userJsonArray()); addSubId(root); return root.toString(); }
25. LinkCodec#encode()
Project: onos
File: LinkCodec.java
File: LinkCodec.java
@Override public ObjectNode encode(Link link, CodecContext context) { checkNotNull(link, "Link cannot be null"); JsonCodec<ConnectPoint> codec = context.codec(ConnectPoint.class); ObjectNode result = context.mapper().createObjectNode(); result.set(SRC, codec.encode(link.src(), context)); result.set(DST, codec.encode(link.dst(), context)); result.put(TYPE, link.type().toString()); if (link.state() != null) { result.put(STATE, link.state().toString()); } return annotate(result, link, context); }
26. TopoJson#json()
Project: onos
File: TopoJson.java
File: TopoJson.java
/** * Transforms the given highlights model into a JSON message payload. * * @param highlights the model to transform * @return JSON payload */ public static ObjectNode json(Highlights highlights) { ObjectNode payload = objectNode(); ArrayNode devices = arrayNode(); ArrayNode hosts = arrayNode(); ArrayNode links = arrayNode(); payload.set(DEVICES, devices); payload.set(HOSTS, hosts); payload.set(LINKS, links); highlights.devices().forEach( dh -> devices.add(json(dh))); highlights.hosts().forEach( hh -> hosts.add(json(hh))); highlights.links().forEach( lh -> links.add(json(lh))); Highlights.Amount toSubdue = highlights.subdueLevel(); if (!toSubdue.equals(Highlights.Amount.ZERO)) { payload.put(SUBDUE, toSubdue.toString()); } int delay = highlights.delayMs(); if (delay > 0) { payload.put(DELAY, delay); } return payload; }
27. BgpConfig#addSpeaker()
Project: onos
File: BgpConfig.java
File: BgpConfig.java
/** * Adds BGP speaker to configuration. * * @param speaker BGP speaker configuration entry */ public void addSpeaker(BgpSpeakerConfig speaker) { ObjectNode speakerNode = JsonNodeFactory.instance.objectNode(); speakerNode.put(NAME, speaker.name().get()); speakerNode.put(VLAN, speaker.vlan().toString()); speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() + "/" + speaker.connectPoint().port().toString()); ArrayNode peersNode = speakerNode.putArray(PEERS); for (IpAddress peerAddress : speaker.peers()) { peersNode.add(peerAddress.toString()); } ArrayNode speakersArray = bgpSpeakers().isEmpty() ? initBgpConfiguration() : (ArrayNode) object.get(SPEAKERS); speakersArray.add(speakerNode); }
28. TopologyViewMessageHandlerBase#hostMessage()
Project: onos
File: TopologyViewMessageHandlerBase.java
File: TopologyViewMessageHandlerBase.java
// Produces a host event message to the client. protected ObjectNode hostMessage(HostEvent event) { Host host = event.subject(); Host prevHost = event.prevSubject(); String hostType = host.annotations().value(AnnotationKeys.TYPE); ObjectNode payload = objectNode().put("id", host.id().toString()).put("type", isNullOrEmpty(hostType) ? "endstation" : hostType).put("ingress", compactLinkString(edgeLink(host, true))).put("egress", compactLinkString(edgeLink(host, false))); payload.set("cp", hostConnect(host.location())); if (prevHost != null && prevHost.location() != null) { payload.set("prevCp", hostConnect(prevHost.location())); } payload.set("labels", labels(ip(host.ipAddresses()), host.mac().toString())); payload.set("props", props(host.annotations())); addGeoLocation(host, payload); addMetaUi(host.id().toString(), payload); String type = HOST_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); }
29. DocumentsTest#setup()
Project: Ektorp
File: DocumentsTest.java
File: DocumentsTest.java
@Before public void setup() { testDoc_1.setId("id_1"); testDoc_1.setRevision("rev_1"); annotatedDoc.setIdentifikator("id_2"); annotatedDoc.setRevisjon("rev_2"); privAnnotatedDoc.setIdentifikator("id_3"); privAnnotatedDoc.setRevisjon("id_3"); mapDoc.put("_id", "id_4"); mapDoc.put("_rev", "rev_4"); ObjectMapper om = new ObjectMapper(); ObjectNode onode = om.createObjectNode(); onode.put("_id", "jsonNode_id"); onode.put("_rev", "jsonNode_rev"); onode.put("otherField", "otherValue"); nodeDoc = onode; }
30. SchemaRuleTest#enumAsRootIsGeneratedCorrectly()
Project: jsonschema2pojo
File: SchemaRuleTest.java
File: SchemaRuleTest.java
@Test public void enumAsRootIsGeneratedCorrectly() throws URISyntaxException, JClassAlreadyExistsException { ObjectNode schemaContent = new ObjectMapper().createObjectNode(); ObjectNode enumNode = schemaContent.objectNode(); enumNode.put("type", "string"); schemaContent.put("enum", enumNode); JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME); Schema schema = mock(Schema.class); when(schema.getContent()).thenReturn(schemaContent); schema.setJavaTypeIfEmpty(jclass); EnumRule enumRule = mock(EnumRule.class); when(mockRuleFactory.getEnumRule()).thenReturn(enumRule); when(enumRule.apply(NODE_NAME, enumNode, jclass, schema)).thenReturn(jclass); rule.apply(NODE_NAME, schemaContent, jclass, schema); verify(enumRule).apply(NODE_NAME, schemaContent, jclass, schema); verify(schema, atLeastOnce()).setJavaTypeIfEmpty(jclass); }
31. FragmentResolverTest#hashResolvesToRoot()
Project: jsonschema2pojo
File: FragmentResolverTest.java
File: FragmentResolverTest.java
@Test public void hashResolvesToRoot() { ObjectNode root = new ObjectMapper().createObjectNode(); root.put("child1", root.objectNode()); root.put("child2", root.objectNode()); root.put("child3", root.objectNode()); assertThat((ObjectNode) resolver.resolve(root, "#"), is(sameInstance(root))); }
32. SchemaGenerator#objectSchema()
Project: jsonschema2pojo
File: SchemaGenerator.java
File: SchemaGenerator.java
private ObjectNode objectSchema(JsonNode exampleObject) { ObjectNode schema = OBJECT_MAPPER.createObjectNode(); schema.put("type", "object"); ObjectNode properties = OBJECT_MAPPER.createObjectNode(); for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext(); ) { String property = iter.next(); properties.put(property, schemaFromExample(exampleObject.get(property))); } schema.put("properties", properties); return schema; }
33. DruidSinkIT#getEvent()
Project: Ingestion
File: DruidSinkIT.java
File: DruidSinkIT.java
private Event getEvent(long offset) { ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("field1", "foo"); jsonBody.put("field2", 32); jsonBody.put("timestamp", String.valueOf(new Date().getTime())); Map<String, String> headers = new HashMap<String, String>(); // Overwrites the value defined in JSON body headers.put("field3", "bar"); headers.put("field4", "64"); headers.put("field5", "true"); headers.put("field6", "1.0"); headers.put("field7", "11"); final long l = new Date().getTime(); headers.put("timestamp", String.valueOf(l + offset)); headers.put("myString2", "baz"); return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); }
34. SyndEntryActivitySerializer#addRomeExtension()
Project: incubator-streams
File: SyndEntryActivitySerializer.java
File: SyndEntryActivitySerializer.java
/** * Given an RSS object and an existing activity, * add the Rome extension to that activity and return it * * @param activity * @param entry * @return */ private Activity addRomeExtension(Activity activity, ObjectNode entry) { ObjectMapper mapper = StreamsJacksonMapper.getInstance(); ObjectNode activityRoot = mapper.convertValue(activity, ObjectNode.class); ObjectNode extensions = JsonNodeFactory.instance.objectNode(); extensions.put("rome", entry); activityRoot.put("extensions", extensions); activity = mapper.convertValue(activityRoot, Activity.class); return activity; }
35. JSONUtilities#replaceLink()
Project: olingo-odata4
File: JSONUtilities.java
File: JSONUtilities.java
@Override protected InputStream replaceLink(final InputStream toBeChanged, final String linkName, final InputStream replacement) throws IOException { final ObjectNode toBeChangedNode = (ObjectNode) mapper.readTree(toBeChanged); final ObjectNode replacementNode = (ObjectNode) mapper.readTree(replacement); if (toBeChangedNode.get(linkName + Constants.get(ConstantKey.JSON_NAVIGATION_SUFFIX)) == null) { throw new NotFoundException(); } toBeChangedNode.set(linkName, replacementNode.get(Constants.get(ConstantKey.JSON_VALUE_NAME))); final JsonNode next = replacementNode.get(linkName + Constants.get(ConstantKey.JSON_NEXTLINK_NAME)); if (next != null) { toBeChangedNode.set(linkName + Constants.get(ConstantKey.JSON_NEXTLINK_SUFFIX), next); } return IOUtils.toInputStream(toBeChangedNode.toString(), Constants.ENCODING); }
36. VersionedAvroEntityMapper#getManagedSchemaEntityVersionSchema()
Project: kite
File: VersionedAvroEntityMapper.java
File: VersionedAvroEntityMapper.java
private static String getManagedSchemaEntityVersionSchema(String entityName) { String avroSchemaString = AvroUtils.inputStreamToString(VersionedAvroEntityMapper.class.getResourceAsStream("/ManagedSchemaEntityVersion.avsc")); JsonNode jsonNode = rawSchemaAsJsonNode(avroSchemaString); ObjectMapper mapper = new ObjectMapper(); ObjectNode mappingNode = mapper.createObjectNode(); mappingNode.put("type", "column"); mappingNode.put("value", "_s:sv_" + entityName); ((ObjectNode) jsonNode.get("fields").get(0)).put("mapping", mappingNode); return jsonNode.toString(); }
37. TypeRuleTest#applyGeneratesNumberUsingJavaTypeBigDecimal()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberUsingJavaTypeBigDecimal() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); objectNode.put("javaType", "java.math.BigDecimal"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.math.BigDecimal")); }
38. TypeRuleTest#applyGeneratesNumberUsingJavaTypeDouble()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberUsingJavaTypeDouble() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); objectNode.put("javaType", "java.lang.Double"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.lang.Double")); }
39. TypeRuleTest#applyGeneratesNumberUsingJavaTypeDoublePrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberUsingJavaTypeDoublePrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); objectNode.put("javaType", "double"); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("double")); }
40. TypeRuleTest#applyGeneratesNumberUsingJavaTypeFloat()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberUsingJavaTypeFloat() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); objectNode.put("javaType", "java.lang.Float"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.lang.Float")); }
41. TypeRuleTest#applyGeneratesNumberUsingJavaTypeFloatPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberUsingJavaTypeFloatPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); objectNode.put("javaType", "float"); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("float")); }
42. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeBigInteger()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeBigInteger() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("javaType", "java.math.BigInteger"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.math.BigInteger")); }
43. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("minimum", Integer.MAX_VALUE + 1L); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Long.class.getName())); }
44. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumGreaterThanIntegerMax()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumGreaterThanIntegerMax() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("minimum", Integer.MAX_VALUE + 1L); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("long")); }
45. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongWhenMinimumLessThanIntegerMin()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongWhenMinimumLessThanIntegerMin() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("minimum", Integer.MIN_VALUE - 1L); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Long.class.getName())); }
46. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumLessThanIntegerMin()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumLessThanIntegerMin() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("minimum", Integer.MIN_VALUE - 1L); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("long")); }
47. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongWhenMaximumLessThanIntegerMin()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongWhenMaximumLessThanIntegerMin() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("maximum", Integer.MIN_VALUE - 1L); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Long.class.getName())); }
48. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumLessThanIntegerMin()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumLessThanIntegerMin() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("maximum", Integer.MIN_VALUE - 1L); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("long")); }
49. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongWhenMaximumGreaterThanIntegerMax()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongWhenMaximumGreaterThanIntegerMax() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("maximum", Integer.MAX_VALUE + 1L); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Long.class.getName())); }
50. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumGreaterThanIntegerMax()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumGreaterThanIntegerMax() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("maximum", Integer.MAX_VALUE + 1L); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("long")); }
51. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLong()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLong() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("javaType", "java.lang.Long"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.lang.Long")); }
52. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeLongPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeLongPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("javaType", "long"); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("long")); }
53. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeInteger()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeInteger() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("javaType", "java.lang.Integer"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("java.lang.Integer")); }
54. TypeRuleTest#applyGeneratesIntegerUsingJavaTypeIntegerPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerUsingJavaTypeIntegerPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); objectNode.put("javaType", "int"); when(config.isUsePrimitives()).thenReturn(false); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("int")); }
55. TypeRuleTest#applyGeneratesDate()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@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.put("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)); }
56. EnumRuleTest#applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName()
Project: jsonschema2pojo
File: EnumRuleTest.java
File: EnumRuleTest.java
@Test public void applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName() { Answer<String> firstArgAnswer = new FirstArgAnswer<String>(); when(nameHelper.getFieldName(anyString(), any(JsonNode.class))).thenAnswer(firstArgAnswer); when(nameHelper.replaceIllegalCharacters(anyString())).thenAnswer(firstArgAnswer); when(nameHelper.normalizeName(anyString())).thenAnswer(firstArgAnswer); JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectMapper objectMapper = new ObjectMapper(); ArrayNode arrayNode = objectMapper.createArrayNode(); arrayNode.add("open"); arrayNode.add("closed"); ObjectNode enumNode = objectMapper.createObjectNode(); enumNode.put("type", "string"); enumNode.put("enum", arrayNode); JType result1 = rule.apply("status", enumNode, jpackage, schema); JType result2 = rule.apply("status", enumNode, jpackage, schema); assertThat(result1.fullName(), is("org.jsonschema2pojo.rules.Status")); assertThat(result2.fullName(), is("org.jsonschema2pojo.rules.Status_")); }
57. JsonRpcBasicServer#createResponseSuccess()
Project: jsonrpc4j
File: JsonRpcBasicServer.java
File: JsonRpcBasicServer.java
/** * Creates a success response. * * @param jsonRpc the version string * @param id the id of the request * @param result the result object * @return the response object */ private ObjectNode createResponseSuccess(String jsonRpc, Object id, JsonNode result) { ObjectNode response = mapper.createObjectNode(); response.put(JSONRPC, jsonRpc); if (Integer.class.isInstance(id)) { response.put(ID, Integer.class.cast(id).intValue()); } else if (Long.class.isInstance(id)) { response.put(ID, Long.class.cast(id).longValue()); } else if (Float.class.isInstance(id)) { response.put(ID, Float.class.cast(id).floatValue()); } else if (Double.class.isInstance(id)) { response.put(ID, Double.class.cast(id).doubleValue()); } else if (BigDecimal.class.isInstance(id)) { response.put(ID, BigDecimal.class.cast(id)); } else { response.put(ID, String.class.cast(id)); } response.set(RESULT, result); return response; }
58. JWTSigner#encodedHeader()
Project: java-jwt
File: JWTSigner.java
File: JWTSigner.java
/** * Generate the header part of a JSON web token. */ private String encodedHeader(Algorithm algorithm) throws UnsupportedEncodingException { if (algorithm == null) { // default the algorithm if not specified algorithm = Algorithm.HS256; } // create the header ObjectNode header = JsonNodeFactory.instance.objectNode(); header.put("typ", "JWT"); header.put("alg", algorithm.name()); return base64UrlEncode(header.toString().getBytes("UTF-8")); }
59. EventParserTest#createEvent()
Project: Ingestion
File: EventParserTest.java
File: EventParserTest.java
private Event createEvent(String index) { ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("field1" + index, "foo"); jsonBody.put("field2" + index, 32); Map<String, String> headers = new HashMap<String, String>(); headers.put("header1" + index, "bar"); headers.put("header2" + index, "64"); headers.put("header3" + index, "true"); headers.put("header4" + index, "1.0"); headers.put("header5" + index, null); return EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); }
60. TestRetry#configurePartly()
Project: incubator-taverna-engine
File: TestRetry.java
File: TestRetry.java
@Test public void configurePartly() throws Exception { Retry retry = new Retry(15, 150, 1200, 1.2); ObjectNode conf = JsonNodeFactory.instance.objectNode(); conf.put("maxRetries", 15); conf.put("backoffFactor", 1.2); retry.configure(conf); // We would expect to see the new values JsonNode configuration = retry.getConfiguration(); assertEquals(15, configuration.get("maxRetries").intValue()); assertEquals(1.2, configuration.get("backoffFactor").doubleValue(), 0.001); // And the default values (not the previous values!) assertEquals(1000, configuration.get("initialDelay").intValue()); assertEquals(5000, configuration.get("maxDelay").intValue()); }
61. RemoteLogUploaderEventListener#putInSink()
Project: buck
File: RemoteLogUploaderEventListener.java
File: RemoteLogUploaderEventListener.java
private void putInSink(BuildId buildId, Object object) { if (failureCount.get() > MAX_FAILURE_COUNT) { return; } sentEventsCount++; ObjectNode jsonNode = mapper.valueToTree(object); jsonNode.put("@class", object.getClass().getCanonicalName()); jsonNode.put("buildId", buildId.toString()); Optional<ListenableFuture<Void>> upload = remoteLogger.log(jsonNode.toString()); if (upload.isPresent()) { registerPendingUpload(upload.get()); } }
62. Dataset#getWatchedUrnId()
Project: WhereHows
File: Dataset.java
File: Dataset.java
public static Result getWatchedUrnId() { ObjectNode result = Json.newObject(); String urn = request().getQueryString("urn"); result.put("status", "success"); Long id = 0L; if (StringUtils.isNotBlank(urn)) { String username = session("user"); if (StringUtils.isNotBlank(username)) { id = DatasetsDAO.getWatchId(urn, username); } } result.put("id", id); return ok(result); }
63. UserDao#getWatchers()
Project: WhereHows
File: UserDao.java
File: UserDao.java
public static ObjectNode getWatchers(String datasetName) { List<String> watchUsers = new ArrayList<String>(); if (StringUtils.isNotBlank(datasetName)) { Map<String, Object> params = new HashMap<>(); params.put("name", datasetName); List<Map<String, Object>> rows = null; rows = JdbcUtil.wherehowsNamedJdbcTemplate.queryForList(GET_USERS_WATCHED_DATASET, params); for (Map row : rows) { String userName = (String) row.get("username"); watchUsers.add(userName); } } ObjectNode result = Json.newObject(); result.put("count", watchUsers.size()); result.set("users", Json.toJson(watchUsers)); return result; }
64. HostURLFilterTest#createFilter()
Project: storm-crawler
File: HostURLFilterTest.java
File: HostURLFilterTest.java
private HostURLFilter createFilter(boolean ignoreOutsideHost, boolean ignoreOutsideDomain) { HostURLFilter filter = new HostURLFilter(); ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("ignoreOutsideHost", Boolean.valueOf(ignoreOutsideHost)); filterParams.put("ignoreOutsideDomain", Boolean.valueOf(ignoreOutsideDomain)); Map<String, Object> conf = new HashMap<>(); filter.configure(conf, filterParams); return filter; }
65. UiWebSocket#sendBootstrapData()
Project: onos
File: UiWebSocket.java
File: UiWebSocket.java
// Sends initial information (username and cluster member information) // to allow GUI to display logged-in user, and to be able to // fail-over to an alternate cluster member if necessary. private void sendBootstrapData() { ClusterService service = directory.get(ClusterService.class); ArrayNode instances = mapper.createArrayNode(); for (ControllerNode node : service.getNodes()) { ObjectNode instance = mapper.createObjectNode().put(ID, node.id().toString()).put(IP, node.ip().toString()).put(TopoConstants.Glyphs.UI_ATTACHED, node.equals(service.getLocalNode())); instances.add(instance); } ObjectNode payload = mapper.createObjectNode(); payload.set(CLUSTER_NODES, instances); payload.put(USER, userName); sendMessage(BOOTSTRAP, 0, payload); }
66. TopologyViewMessageHandlerBase#deviceMessage()
Project: onos
File: TopologyViewMessageHandlerBase.java
File: TopologyViewMessageHandlerBase.java
// Produces a device event message to the client. protected ObjectNode deviceMessage(DeviceEvent event) { Device device = event.subject(); ObjectNode payload = objectNode().put("id", device.id().toString()).put("type", device.type().toString().toLowerCase()).put("online", deviceService.isAvailable(device.id())).put("master", master(device.id())); // Generate labels: id, chassis id, no-label, optional-name String name = device.annotations().value(AnnotationKeys.NAME); ArrayNode labels = arrayNode(); labels.add(""); labels.add(isNullOrEmpty(name) ? device.id().toString() : name); labels.add(device.id().toString()); // Add labels, props and stuff the payload into envelope. payload.set("labels", labels); payload.set("props", props(device.annotations())); addGeoLocation(device, payload); addMetaUi(device.id().toString(), payload); String type = DEVICE_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); }
67. TopologyResource#addGeoData()
Project: onos
File: TopologyResource.java
File: TopologyResource.java
private void addGeoData(ArrayNode array, String idField, String id, ObjectNode memento) { ObjectNode node = mapper.createObjectNode().put(idField, id); ObjectNode annot = mapper.createObjectNode(); node.set("annotations", annot); try { annot.put("latitude", memento.get("lat").asDouble()).put("longitude", memento.get("lng").asDouble()); array.add(node); } catch (Exception e) { log.debug("Skipping geo entry"); } }
68. TopologyResource#getGeoLocations()
Project: onos
File: TopologyResource.java
File: TopologyResource.java
@Path("geoloc") @GET @Produces("application/json") public Response getGeoLocations() { ObjectNode rootNode = mapper.createObjectNode(); ArrayNode devices = mapper.createArrayNode(); ArrayNode hosts = mapper.createArrayNode(); Map<String, ObjectNode> metaUi = TopologyViewMessageHandler.getMetaUi(); for (String id : metaUi.keySet()) { ObjectNode memento = metaUi.get(id); if (id.length() > 17 && id.charAt(17) == '/') { addGeoData(hosts, "id", id, memento); } else { addGeoData(devices, "uri", id, memento); } } rootNode.set("devices", devices); rootNode.set("hosts", hosts); return Response.ok(rootNode.toString()).build(); }
69. StatisticsWebResource#getPortStatisticsByDeviceId()
Project: onos
File: StatisticsWebResource.java
File: StatisticsWebResource.java
/** * Gets port statistics of a specified devices. * @onos.rsModel StatisticsPorts * @param deviceId device ID * @return 200 OK with JSON encoded array of port statistics */ @GET @Path("ports/{deviceId}") @Produces(MediaType.APPLICATION_JSON) public Response getPortStatisticsByDeviceId(@PathParam("deviceId") String deviceId) { final DeviceService service = get(DeviceService.class); final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(DeviceId.deviceId(deviceId)); final ObjectNode root = mapper().createObjectNode(); final ArrayNode rootArrayNode = root.putArray("statistics"); final ObjectNode deviceStatsNode = mapper().createObjectNode(); deviceStatsNode.put("device", deviceId); final ArrayNode statisticsNode = deviceStatsNode.putArray("ports"); if (portStatsEntries != null) { for (final PortStatistics entry : portStatsEntries) { statisticsNode.add(codec(PortStatistics.class).encode(entry, this)); } } rootArrayNode.add(deviceStatsNode); return ok(root).build(); }
70. StatisticsWebResource#getTableStatisticsByDeviceId()
Project: onos
File: StatisticsWebResource.java
File: StatisticsWebResource.java
/** * Gets table statistics for all tables of a specified device. * * @onos.rsModel StatisticsFlowsTables * @param deviceId device ID * @return 200 OK with JSON encoded array of table statistics */ @GET @Path("flows/tables/{deviceId}") @Produces(MediaType.APPLICATION_JSON) public Response getTableStatisticsByDeviceId(@PathParam("deviceId") String deviceId) { final FlowRuleService service = get(FlowRuleService.class); final Iterable<TableStatisticsEntry> tableStatisticsEntries = service.getFlowTableStatistics(DeviceId.deviceId(deviceId)); final ObjectNode root = mapper().createObjectNode(); final ArrayNode rootArrayNode = root.putArray("statistics"); final ObjectNode deviceStatsNode = mapper().createObjectNode(); deviceStatsNode.put("device", deviceId); final ArrayNode statisticsNode = deviceStatsNode.putArray("table"); for (final TableStatisticsEntry entry : tableStatisticsEntries) { statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this)); } rootArrayNode.add(deviceStatsNode); return ok(root).build(); }
71. MetricCodecTest#testMetricEncode()
Project: onos
File: MetricCodecTest.java
File: MetricCodecTest.java
/** * Tests encoding of a Metric object. */ @Test public void testMetricEncode() { Counter counter = new Counter(); Meter meter = new Meter(); Timer timer = new Timer(); counter.inc(); meter.mark(); timer.update(1, TimeUnit.MILLISECONDS); ObjectNode counterJson = metricCodec.encode(counter, context); assertThat(counterJson.get("counter"), matchesMetric(counter)); ObjectNode meterJson = metricCodec.encode(meter, context); assertThat(meterJson.get("meter"), matchesMetric(meter)); ObjectNode timerJson = metricCodec.encode(timer, context); assertThat(timerJson.get("timer"), matchesMetric(timer)); }
72. HostToHostIntentCodec#encode()
Project: onos
File: HostToHostIntentCodec.java
File: HostToHostIntentCodec.java
@Override public ObjectNode encode(HostToHostIntent intent, CodecContext context) { checkNotNull(intent, "Host to host intent cannot be null"); final JsonCodec<ConnectivityIntent> connectivityIntentCodec = context.codec(ConnectivityIntent.class); final ObjectNode result = connectivityIntentCodec.encode(intent, context); final String one = intent.one().toString(); final String two = intent.two().toString(); result.put(ONE, one); result.put(TWO, two); return result; }
73. HostCodec#encode()
Project: onos
File: HostCodec.java
File: HostCodec.java
@Override public ObjectNode encode(Host host, CodecContext context) { checkNotNull(host, "Host cannot be null"); final JsonCodec<HostLocation> locationCodec = context.codec(HostLocation.class); final ObjectNode result = context.mapper().createObjectNode().put("id", host.id().toString()).put("mac", host.mac().toString()).put("vlan", host.vlan().toString()); final ArrayNode jsonIpAddresses = result.putArray("ipAddresses"); for (final IpAddress ipAddress : host.ipAddresses()) { jsonIpAddresses.add(ipAddress.toString()); } result.set("ipAddresses", jsonIpAddresses); result.set("location", locationCodec.encode(host.location(), context)); return annotate(result, host, context); }
74. TableRequestHandler#process()
Project: onos
File: TableRequestHandler.java
File: TableRequestHandler.java
@Override public void process(long sid, ObjectNode payload) { TableModel tm = createTableModel(); populateTable(tm, payload); String firstCol = JsonUtils.string(payload, FIRST_COL, defaultColumnId()); String firstDir = JsonUtils.string(payload, FIRST_DIR, ASC); String secondCol = JsonUtils.string(payload, SECOND_COL, null); String secondDir = JsonUtils.string(payload, SECOND_DIR, null); tm.sort(firstCol, sortDir(firstDir), secondCol, sortDir(secondDir)); addTableConfigAnnotations(tm, payload); ObjectNode rootNode = MAPPER.createObjectNode(); rootNode.set(nodeName, TableUtils.generateRowArrayNode(tm)); rootNode.set(ANNOTS, TableUtils.generateAnnotObjectNode(tm)); sendMessage(respType, 0, rootNode); }
75. DevicePortsListCommand#jsonPorts()
Project: onos
File: DevicePortsListCommand.java
File: DevicePortsListCommand.java
/** * Produces JSON array containing ports of the specified device. * * @param service device service * @param mapper object mapper * @param device infrastructure devices * @return JSON array */ public JsonNode jsonPorts(DeviceService service, ObjectMapper mapper, Device device) { ObjectNode result = mapper.createObjectNode(); ArrayNode ports = mapper.createArrayNode(); for (Port port : service.getPorts(device.id())) { if (isIncluded(port)) { ports.add(mapper.createObjectNode().put("port", portName(port.number())).put("isEnabled", port.isEnabled()).put("type", port.type().toString().toLowerCase()).put("portSpeed", port.portSpeed()).set("annotations", annotations(mapper, port.annotations()))); } } result.set("device", jsonForEntity(device, Device.class)); result.set("ports", ports); return result; }
76. SubnetCodec#encode()
Project: onos
File: SubnetCodec.java
File: SubnetCodec.java
@Override public ObjectNode encode(Subnet subnet, CodecContext context) { checkNotNull(subnet, "Subnet cannot be null"); ObjectNode result = context.mapper().createObjectNode().put("id", subnet.id().toString()).put("gateway_ip", subnet.gatewayIp().toString()).put("network_id", subnet.networkId().toString()).put("name", subnet.subnetName()).put("ip_version", subnet.ipVersion().toString()).put("cidr", subnet.cidr().toString()).put("shared", subnet.shared()).put("enabled_dchp", subnet.dhcpEnabled()).put("tenant_id", subnet.tenantId().toString()).put("ipv6_address_mode", subnet.ipV6AddressMode() == null ? null : subnet.ipV6AddressMode().toString()).put("ipv6_ra_mode", subnet.ipV6RaMode() == null ? null : subnet.ipV6RaMode().toString()); result.set("allocation_pools", new AllocationPoolsCodec().encode(subnet.allocationPools(), context)); result.set("host_routes", new HostRoutesCodec().encode(subnet.hostRoutes(), context)); return result; }
77. PcePathCodec#encode()
Project: onos
File: PcePathCodec.java
File: PcePathCodec.java
@Override public ObjectNode encode(PcePath path, CodecContext context) { checkNotNull(path, "path output cannot be null"); ObjectNode result = context.mapper().createObjectNode().put(PATH_ID, path.id().id()).put(SOURCE, path.source()).put(DESTINATION, path.destination()).put(LSP_TYPE, path.lspType().type()).put(SYMBOLIC_PATH_NAME, path.name()); ObjectNode constraintNode = context.mapper().createObjectNode().put(COST, path.costConstraint().toString()).put(BANDWIDTH, path.bandwidthConstraint().toString()); result.set(CONSTRAINT, constraintNode); return result; }
78. CordModelCache#jsonUsers()
Project: onos
File: CordModelCache.java
File: CordModelCache.java
/** * Returns the users page data as JSON. * * @return users page JSON data */ public synchronized String jsonUsers() { log.info("jsonUsers()"); if (email == null) { return jsonLogout(); } ObjectNode root = objectNode(); root.set(USERS, userJsonArray()); addSubId(root); return root.toString(); }
79. JSONUtilities#selectEntity()
Project: olingo-odata4
File: JSONUtilities.java
File: JSONUtilities.java
@Override public InputStream selectEntity(final InputStream src, final String[] propertyNames) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); final Set<String> retain = new HashSet<String>(); retain.add(Constants.get(ConstantKey.JSON_ID_NAME)); retain.add(Constants.get(ConstantKey.JSON_TYPE_NAME)); retain.add(Constants.get(ConstantKey.JSON_EDITLINK_NAME)); retain.add(Constants.get(ConstantKey.JSON_NEXTLINK_NAME)); retain.add(Constants.get(ConstantKey.JSON_ODATAMETADATA_NAME)); retain.add(Constants.get(ConstantKey.JSON_VALUE_NAME)); for (String name : propertyNames) { retain.add(name); retain.add(name + Constants.get(ConstantKey.JSON_NAVIGATION_SUFFIX)); retain.add(name + Constants.get(ConstantKey.JSON_MEDIA_SUFFIX)); retain.add(name + Constants.get(ConstantKey.JSON_TYPE_SUFFIX)); } srcNode.retain(retain); return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); }
80. JsonSerialization#createObjectNode()
Project: keycloak
File: JsonSerialization.java
File: JsonSerialization.java
/** * Creates an {@link ObjectNode} based on the given {@code pojo}, copying all its properties to the resulting {@link ObjectNode}. * * @param pojo a pojo which properties will be populates into the resulting a {@link ObjectNode} * @return a {@link ObjectNode} with all the properties from the given pojo * @throws IOException if the resulting a {@link ObjectNode} can not be created */ public static ObjectNode createObjectNode(Object pojo) throws IOException { if (pojo == null) { throw new IllegalArgumentException("Pojo can not be null."); } ObjectNode objectNode = createObjectNode(); JsonParser jsonParser = mapper.getJsonFactory().createJsonParser(writeValueAsBytes(pojo)); JsonNode jsonNode = jsonParser.readValueAsTree(); if (!jsonNode.isObject()) { throw new RuntimeException("JsonNode [" + jsonNode + "] is not a object."); } objectNode.putAll((ObjectNode) jsonNode); return objectNode; }
81. MediaIT#roundTripAssertions()
Project: jsonschema2pojo
File: MediaIT.java
File: MediaIT.java
public static void roundTripAssertions(ObjectMapper objectMapper, String propertyName, String jsonValue, Object javaValue) throws Exception { ObjectNode node = objectMapper.createObjectNode(); node.put(propertyName, jsonValue); Object pojo = objectMapper.treeToValue(node, classWithMediaProperties); Method getter = new PropertyDescriptor(propertyName, classWithMediaProperties).getReadMethod(); assertThat(getter.invoke(pojo), is(equalTo(javaValue))); JsonNode jsonVersion = objectMapper.valueToTree(pojo); assertThat(jsonVersion.get(propertyName).asText(), is(equalTo(jsonValue))); }
82. FormatIT#valueCanBeSerializedAndDeserialized()
Project: jsonschema2pojo
File: FormatIT.java
File: FormatIT.java
@Test public void valueCanBeSerializedAndDeserialized() throws NoSuchMethodException, IOException, IntrospectionException, IllegalAccessException, InvocationTargetException { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode node = objectMapper.createObjectNode(); node.put(propertyName, jsonValue.toString()); Object pojo = objectMapper.treeToValue(node, classWithFormattedProperties); Method getter = new PropertyDescriptor(propertyName, classWithFormattedProperties).getReadMethod(); assertThat(getter.invoke(pojo).toString(), is(equalTo(javaValue.toString()))); JsonNode jsonVersion = objectMapper.valueToTree(pojo); assertThat(jsonVersion.get(propertyName).asText(), is(equalTo(jsonValue.toString()))); }
83. TypeRuleTest#applyChoosesObjectOnUnrecognizedType()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyChoosesObjectOnUnrecognizedType() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "unknown"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Object.class.getName())); }
84. TypeRuleTest#applyGeneratesCustomObject()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesCustomObject() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "object"); JDefinedClass mockObjectType = mock(JDefinedClass.class); ObjectRule mockObjectRule = mock(ObjectRule.class); when(mockObjectRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockObjectType); when(ruleFactory.getObjectRule()).thenReturn(mockObjectRule); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result, is((JType) mockObjectType)); }
85. TypeRuleTest#applyGeneratesArray()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesArray() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "array"); JClass mockArrayType = mock(JClass.class); ArrayRule mockArrayRule = mock(ArrayRule.class); when(mockArrayRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockArrayType); when(ruleFactory.getArrayRule()).thenReturn(mockArrayRule); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result, is((JType) mockArrayType)); }
86. TypeRuleTest#applyGeneratesNullAsObject()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNullAsObject() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "null"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Object.class.getName())); }
87. TypeRuleTest#applyGeneratesAnyAsObject()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesAnyAsObject() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "any"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Object.class.getName())); }
88. TypeRuleTest#applyGeneratesBooleanPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesBooleanPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "boolean"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("boolean")); }
89. TypeRuleTest#applyGeneratesBoolean()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesBoolean() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "boolean"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Boolean.class.getName())); }
90. TypeRuleTest#applyGeneratesNumberPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumberPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); when(config.isUsePrimitives()).thenReturn(true); when(config.isUseDoubleNumbers()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("double")); }
91. TypeRuleTest#applyGeneratesNumber()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesNumber() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); when(config.isUseDoubleNumbers()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Double.class.getName())); }
92. TypeRuleTest#applyGeneratesBigDecimal_2()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesBigDecimal_2() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); //this shows that isUseBigDecimals overrides isUseDoubleNumbers when(config.isUseDoubleNumbers()).thenReturn(true); when(config.isUseBigDecimals()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(BigDecimal.class.getName())); }
93. TypeRuleTest#applyGeneratesBigDecimal_1()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesBigDecimal_1() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "number"); when(config.isUseBigDecimals()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(BigDecimal.class.getName())); }
94. TypeRuleTest#applyGeneratesIntegerPrimitive()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesIntegerPrimitive() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); when(config.isUsePrimitives()).thenReturn(true); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is("int")); }
95. TypeRuleTest#applyGeneratesInteger()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesInteger() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "integer"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(Integer.class.getName())); }
96. TypeRuleTest#applyGeneratesString()
Project: jsonschema2pojo
File: TypeRuleTest.java
File: TypeRuleTest.java
@Test public void applyGeneratesString() { JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName()); ObjectNode objectNode = new ObjectMapper().createObjectNode(); objectNode.put("type", "string"); JType result = rule.apply("fooBar", objectNode, jpackage, null); assertThat(result.fullName(), is(String.class.getName())); }
97. SchemaRuleTest#existingTypeIsUsedWhenTypeIsAlreadyGenerated()
Project: jsonschema2pojo
File: SchemaRuleTest.java
File: SchemaRuleTest.java
@Test public void existingTypeIsUsedWhenTypeIsAlreadyGenerated() throws URISyntaxException { JType previouslyGeneratedType = mock(JType.class); URI schemaUri = getClass().getResource("/schema/address.json").toURI(); SchemaStore schemaStore = new SchemaStore(); Schema schema = schemaStore.create(schemaUri); schema.setJavaType(previouslyGeneratedType); when(mockRuleFactory.getSchemaStore()).thenReturn(schemaStore); ObjectNode schemaNode = new ObjectMapper().createObjectNode(); schemaNode.put("$ref", schemaUri.toString()); JType result = rule.apply(NODE_NAME, schemaNode, null, schema); assertThat(result, is(sameInstance(previouslyGeneratedType))); }
98. FragmentResolverTest#pathCanReferToArrayContentsByIndex()
Project: jsonschema2pojo
File: FragmentResolverTest.java
File: FragmentResolverTest.java
@Test public void pathCanReferToArrayContentsByIndex() { ObjectNode root = new ObjectMapper().createObjectNode(); ArrayNode a = root.arrayNode(); root.put("a", a); a.add(root.objectNode()); a.add(root.objectNode()); a.add(root.objectNode()); assertThat(resolver.resolve(root, "#/a/0"), is(sameInstance(a.get(0)))); assertThat(resolver.resolve(root, "#/a/1"), is(sameInstance(a.get(1)))); assertThat(resolver.resolve(root, "#/a/2"), is(sameInstance(a.get(2)))); }
99. SchemaGenerator#arraySchema()
Project: jsonschema2pojo
File: SchemaGenerator.java
File: SchemaGenerator.java
private ObjectNode arraySchema(JsonNode exampleArray) { ObjectNode schema = OBJECT_MAPPER.createObjectNode(); schema.put("type", "array"); if (exampleArray.size() > 0) { JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0); schema.put("items", schemaFromExample(exampleItem)); } return schema; }
100. NonPojoTest#canFindAndSaveJsonNode()
Project: jongo
File: NonPojoTest.java
File: NonPojoTest.java
@Test public void canFindAndSaveJsonNode() throws Exception { collection.insert("{name:'John'}"); ObjectNode node = collection.findOne().as(ObjectNode.class); node.put("name", "Robert"); collection.save(node); Map result = collection.findOne().as(Map.class); assertThat(result.get("name")).isEqualTo("Robert"); assertThat(result.get("_id")).isNotNull(); }