java-json-tools/json-schema-core

Untie JsonPointer

fge opened this issue · 3 comments

fge commented

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?
fge commented

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.

fge commented

OK, so, here is how it currently stands.

Source files

https://github.com/fge/json-schema-core/tree/master/src/main/java/com/github/fge/jsonschema/jsonpointer

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 a ReferenceToken as an argument. It has one abstract method, .get(), accepting a T as an argument and returning a T. It returns null if there is no such token. Its equals(), hashCode() and toString() are final.
  • JsonNodeResolver: extends TokenResolver<JsonNode>. Takes into account the bizarreness of 00 array indices.
  • TreePointer<T extends TreeNode>: abstract. Has one protected final member which is a List<TokenResolver<T>>. Two protected constructors. Two final methods: .path() and .get(). The difference is as for JsonNode, except more general: if .get() returns null, .path() will return whatever is declared as this class's protected final missing member, which is of type T. Its equals(), hashCode() and toString() are final.
  • JsonPointer: extends TreePointer<JsonNode>.

Tests

https://github.com/fge/json-schema-core/tree/master/src/test/java/com/github/fge/jsonschema/jsonpointer

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?

fge commented

Irrelevant, Jackson has decided to go its own route for 2.3.x.