@ParametersAreNonnullByDefault
public final class MutableJsonTree
extends java.lang.Object
Navigation through the tree is done using JsonPointer
s.
Note that JsonNode
is mutable. This means that at init
time we make a copy of the node given as argument (using JsonNode.deepCopy()
, but after that all nodes returned by getCurrentNode()
are mutable. Changes you make to the returned node
therefore will be reflected in the result.
While you can do that, it is advised that you use SwaggerMigrator
s
instead and make use of the applyMigrator(SwaggerMigrator)
and
applyMigratorToElements(SwaggerMigrator)
methods.
Constructor and Description |
---|
MutableJsonTree(com.fasterxml.jackson.databind.JsonNode node)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
appendPointer(com.github.fge.jackson.jsonpointer.JsonPointer pointer)
Relative pointer change
|
void |
applyMigrator(SwaggerMigrator migrator)
Apply a migrator to the node at the current pointer
|
void |
applyMigratorToElements(SwaggerMigrator migrator)
Apply a migrator to all elements of the array at the current pointer
|
void |
applyPatch(com.github.fge.jsonpatch.JsonPatch patch)
Apply a JSON Patch to the current node
|
void |
applyPatchToElements(com.github.fge.jsonpatch.JsonPatch patch)
Apply a JSON Patch to all elements of a JSON Array
|
com.fasterxml.jackson.databind.JsonNode |
getBaseNode()
Return the base node
|
com.fasterxml.jackson.databind.JsonNode |
getCurrentNode()
Get the value at the current pointer (always guaranteed to exist)
|
void |
setPointer(com.github.fge.jackson.jsonpointer.JsonPointer pointer)
Absolute pointer change
|
java.lang.String |
toString() |
public MutableJsonTree(com.fasterxml.jackson.databind.JsonNode node)
node
- the node to transform (copied)public void setPointer(com.github.fge.jackson.jsonpointer.JsonPointer pointer)
The new current node will be the node at this pointer starting from the base node.
pointer
- the pointerjava.lang.IllegalArgumentException
- no JSON value at given pointerpublic void appendPointer(com.github.fge.jackson.jsonpointer.JsonPointer pointer)
The pointer in argument is appended to the current pointer (using
JsonPointer.append(JsonPointer)
) and the current node is set
accordingly.
pointer
- the pointer to appendjava.lang.IllegalArgumentException
- no JSON value at given pointerpublic com.fasterxml.jackson.databind.JsonNode getBaseNode()
The "base node" here means the (potentially) altered copy of the node supplied as the constructor argument.
public com.fasterxml.jackson.databind.JsonNode getCurrentNode()
public void applyPatch(com.github.fge.jsonpatch.JsonPatch patch) throws SwaggerMigrationException
This will turn the patch into a SwaggerMigrator
using SwaggerMigrators.fromPatch(JsonPatch)
and call applyMigrator(SwaggerMigrator)
.
patch
- the JSON Patch to applySwaggerMigrationException
- same as applyMigrator(SwaggerMigrator)
public void applyMigrator(SwaggerMigrator migrator) throws SwaggerMigrationException
It is assumed here that the current node is a JSON Object.
migrator
- the migrator to applySwaggerMigrationException
- current node is not an object, or the
migrator failed to applypublic void applyMigratorToElements(SwaggerMigrator migrator) throws SwaggerMigrationException
Note that if the migrator fails to apply to at least one element, the original array is left untouched; its elements are replaced if and only if the migrator applies successfully to all elements.
migrator
- the migrator to applySwaggerMigrationException
- current node is not a JSON Array, or
migrator failed to apply to at least one array elementpublic void applyPatchToElements(com.github.fge.jsonpatch.JsonPatch patch) throws SwaggerMigrationException
This will wrap the patch into a SwaggerMigrator
using SwaggerMigrators.fromPatch(JsonPatch)
and call applyMigratorToElements(SwaggerMigrator)
.
patch
- the JSON Patch to applySwaggerMigrationException
- same as applyMigratorToElements(SwaggerMigrator)
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2019. All Rights Reserved.