Untie JsonPointer
fge opened this issue · 3 comments
JsonPointer will be migrated into this package.
Goal: make it more self contained, for it to be more easily integrated into jackson-core.
Original issue:
java-json-tools/json-schema-validator#38
TODO:
- de-guavaify;
- split
ReferenceToken
; - make it not implement
JsonFragment
(turn the latter into an interface instead); - others?
OK, some news on this front:
- this package now contains a class named
ReferenceToken
, and all code to build a token from a raw or cooked token, or an integer; - it has its own, dedicated exception for the two events where a reference token is invalid: either an empty or an illegal escape seqeunce;
- no resolving yet.
I have also simplified the code a lot in json-schema-validator. This will allow to reuse the code in there.
OK, so, here is how it currently stands.
Source files
The classes there are:
ReferenceToken
: one reference token as specified by the JSON Pointer drafts; it has no public constructor but three static factory methods:.fromRaw()
,.fromCooked()
and.fromInt()
. They take respectively a raw token, a "cooked" (ie, encoded token) an an integer as arguments and build the appropriate tokens. Final.TokenResolver<T extends TreeNode>
: abstract. Its sole protected constructor accepts aReferenceToken
as an argument. It has one abstract method,.get()
, accepting aT
as an argument and returning aT
. It returnsnull
if there is no such token. Itsequals()
,hashCode()
andtoString()
are final.JsonNodeResolver
: extendsTokenResolver<JsonNode>
. Takes into account the bizarreness of00
array indices.TreePointer<T extends TreeNode>
: abstract. Has one protected final member which is aList<TokenResolver<T>>
. Two protected constructors. Two final methods:.path()
and.get()
. The difference is as forJsonNode
, except more general: if.get()
returns null,.path()
will return whatever is declared as this class's protected finalmissing
member, which is of typeT
. Itsequals()
,hashCode()
andtoString()
are final.JsonPointer
: extendsTreePointer<JsonNode>
.
Tests
Everything is fully tested: tree traversal, token building etc.
Left to untie
The exceptions thrown and some sprinkles of Guava here and there -- in particular, ImmutableList
. But on the whole, not much.
For tests, warning: I use TestNG and mockito. Jackson uses neither as this moment.
Comments?
Irrelevant, Jackson has decided to go its own route for 2.3.x.