Java Code Examples for com.fasterxml.jackson.databind.node.ObjectNode#replace()
The following examples show how to use
com.fasterxml.jackson.databind.node.ObjectNode#replace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InPlaceLeftHandMerger.java From bootique with Apache License 2.0 | 6 votes |
protected JsonNode mergeObjects(JsonNode target, JsonNode source) { ObjectNode targetObject = (ObjectNode) target; ObjectNode srcObject = (ObjectNode) source; Iterator<String> fieldNames = srcObject.fieldNames(); while (fieldNames.hasNext()) { String fieldName = fieldNames.next(); JsonNode srcChild = srcObject.get(fieldName); JsonNode targetChild = targetObject.get(fieldName); targetObject.replace(fieldName, apply(targetChild, srcChild)); } return target; }
Example 2
Source File: YamlConfigLoader.java From digdag with Apache License 2.0 | 5 votes |
private void mergeObject(ObjectNode dest, ObjectNode src) { for (Map.Entry<String, JsonNode> pair : ImmutableList.copyOf(src.fields())) { JsonNode d = dest.get(pair.getKey()); JsonNode v = pair.getValue(); if (d != null && d.isObject() && v.isObject()) { mergeObject((ObjectNode) d, (ObjectNode) v); } else { dest.replace(pair.getKey(), v); } } }
Example 3
Source File: Serializer.java From james-project with Apache License 2.0 | 5 votes |
@Override public JsonNode serialize(T serializable) { ArbitrarySerializable.Serializable<T> serialized = serializable.serialize(); ObjectNode serializedJson = JsonNodeFactory.instance.objectNode(); serializedJson.put("deserializer", serialized.getDeserializer().getName()); serializedJson.replace("value", serialized.getValue().toJson()); return serializedJson; }
Example 4
Source File: FlowableBpmnProcessManager.java From syncope with Apache License 2.0 | 5 votes |
protected void exportProcessModel(final String key, final OutputStream os) { Model model = getModel(FlowableRuntimeUtils.getLatestProcDefByKey(engine, key)); try { ObjectNode modelNode = (ObjectNode) OBJECT_MAPPER.readTree(model.getMetaInfo()); modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId()); modelNode.replace(MODEL_DATA_JSON_MODEL, OBJECT_MAPPER.readTree(engine.getRepositoryService().getModelEditorSource(model.getId()))); os.write(modelNode.toString().getBytes()); } catch (IOException e) { LOG.error("While exporting workflow definition {}", model.getId(), e); } }
Example 5
Source File: SchemaGenerationContextImpl.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@Override public ObjectNode makeNullable(ObjectNode node) { final String nullTypeName = this.getKeyword(SchemaKeyword.TAG_TYPE_NULL); if (node.has(this.getKeyword(SchemaKeyword.TAG_REF)) || node.has(this.getKeyword(SchemaKeyword.TAG_ALLOF)) || node.has(this.getKeyword(SchemaKeyword.TAG_ANYOF)) || node.has(this.getKeyword(SchemaKeyword.TAG_ONEOF))) { // cannot be sure what is specified in those other schema parts, instead simply create a oneOf wrapper ObjectNode nullSchema = this.generatorConfig.createObjectNode() .put(this.getKeyword(SchemaKeyword.TAG_TYPE), nullTypeName); ArrayNode anyOf = this.generatorConfig.createArrayNode() // one option in the oneOf should be null .add(nullSchema) // the other option is the given (assumed to be) not-nullable node .add(this.generatorConfig.createObjectNode().setAll(node)); // replace all existing (and already copied properties with the oneOf wrapper node.removeAll(); node.set(this.getKeyword(SchemaKeyword.TAG_ANYOF), anyOf); } else { // given node is a simple schema, we can simply adjust its "type" attribute JsonNode fixedJsonSchemaType = node.get(this.getKeyword(SchemaKeyword.TAG_TYPE)); if (fixedJsonSchemaType instanceof ArrayNode) { // there are already multiple "type" values ArrayNode arrayOfTypes = (ArrayNode) fixedJsonSchemaType; // one of the existing "type" values could be null boolean alreadyContainsNull = false; for (JsonNode arrayEntry : arrayOfTypes) { alreadyContainsNull = alreadyContainsNull || nullTypeName.equals(arrayEntry.textValue()); } if (!alreadyContainsNull) { // null "type" was not mentioned before, to be safe we need to replace the old array and add the null entry node.replace(this.getKeyword(SchemaKeyword.TAG_TYPE), this.generatorConfig.createArrayNode() .addAll(arrayOfTypes) .add(nullTypeName)); } } else if (fixedJsonSchemaType instanceof TextNode && !nullTypeName.equals(fixedJsonSchemaType.textValue())) { // add null as second "type" option node.replace(this.getKeyword(SchemaKeyword.TAG_TYPE), this.generatorConfig.createArrayNode() .add(fixedJsonSchemaType) .add(nullTypeName)); } // if no "type" is specified, null is allowed already } return node; }
Example 6
Source File: SendAmountActivity.java From green_android with GNU General Public License v3.0 | 4 votes |
private void updateTransaction() { if (isFinishing() || mTx == null) return; if (getSession().getNetworkData().getLiquid() && mSelectedAsset.isEmpty()) { mNextButton.setText(R.string.id_select_asset); return; } if (mCurrentAmount == null && !mSendAll) { mNextButton.setText(R.string.id_invalid_amount); return; } if (updateDisposable != null) updateDisposable.dispose(); mTx.replace("send_all", mSendAll ? BooleanNode.TRUE : BooleanNode.FALSE); final ObjectNode addressee = (ObjectNode) mTx.get("addressees").get(0); if (mCurrentAmount != null) { final LongNode satoshi = new LongNode(mCurrentAmount.get("satoshi").asLong()); addressee.replace("satoshi", satoshi); } final LongNode fee_rate = new LongNode(mFeeEstimates[mSelectedFee]); mTx.replace("fee_rate", fee_rate); updateDisposable = Observable.just(mTx) .observeOn(Schedulers.computation()) .map((tx) -> { return getSession().createTransactionRaw(null, tx).resolve(null, new HardwareCodeResolver(this)); }) .observeOn(AndroidSchedulers.mainThread()) .subscribe((tx) -> { mTx = tx; // TODO this should be removed when handled in gdk final String error = mTx.get("error").asText(); if (error.isEmpty()) { if (mTx.get("transaction_vsize") != null) mVsize = mTx.get("transaction_vsize").asLong(); updateFeeSummaries(); mNextButton.setText(R.string.id_review); } else { mNextButton.setText(UI.i18n(getResources(), error)); } UI.enableIf(error.isEmpty(), mNextButton); }, (e) -> { e.printStackTrace(); UI.toast(this, R.string.id_operation_failure, Toast.LENGTH_LONG); finishOnUiThread(); }); }
Example 7
Source File: AttributeValue.java From james-project with Apache License 2.0 | 4 votes |
public JsonNode toJson() { ObjectNode serialized = JsonNodeFactory.instance.objectNode(); serialized.put("serializer", serializer.getName()); serialized.replace("value", serializer.serialize(value)); return serialized; }