feat: record based validation schemas#86
Merged
Merged
Conversation
…nts, some small error handling fixes
|
Contributor
Author
|
I went ahead and merged it as it was in a good state. Instead of review I will do a code and feature walk-through once I finished the TODOs I added in another PR. This PR was getting to big 😅 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




TLDR;
to(Class)API (ah-hoc access based mapping to Java types)record-type based validationto-conversionTBD
API Changes
Changes from upgrading the access concept, mainly introduction of the
to(Class)method and support for mapping to records and using records as validation schemas.? extends JsonObjectrestriction on allClassarguments for a validation schemaJsonTypedAccessStorewithJsonAccessorsJsonValue#getAccessStorewithJsonValue#getAccessorsJsonGenericTypedAccessorwithJsonAccessorJsonTypedAccessorwithSimpleJsonAccessorJsonTypedAccesstoJsonAccessJsonValue#isAccessCachedJsonValue#withAccessCachedJsonAccessExceptionMETHODas@Targetfor@Validation,@Validatorand@ValidatorRepeat(covered byTYPE_USE)METHODas@Targetfor@RequiredwithTYPEandTYPE_USE(coversMETHOD)Changes from upgrading to use
Textviews instead ofStringto represent path segments.JsonObjectandJsonNodeAPI accepting a member name asStringnow accept aCharSequenceJsonNode#isElementto be defined on arrays and objectsJsonPath#toStringnow throws aJsonPathExceptionwhen the path cannot be represented with syntaxJsonMixed,JsonValueandJsonNodeof(Reader)method (usingTextis a better way now)JsonPath#keyOf(no longer needed)JsonPath#shortenedBy(no longer needed)JsonPath#dropFirstSegment(no longer needed)JsonPath#objectMemberAtStart(no longer needed)JsonPath#arrayIndexAtStart(no longer needed)JsonPath#startsWithObject(no longer needed)JsonPath#startsWithArray(no longer needed)JsonPath#ROOTtoSELF(as it not only root but mostly a self reference)JsonPath#sizetolength(more fitting as it is not a collection)JsonPath#dropLastSegmenttoparentPathJsonPath#extendedWithtochain(single element) andconcat(potentially multiple) for clarityJsonPath#extendedWith(Text)JsonNode#memberOrNull(String)JsonNode#member(String)JsonNode#get(Text)JsonNode#getOrNull(Text)JsonNode#member(Text)JsonNode#memberOrNull(Text)JsonNode#isMemberJsonNode#element(Text)JsonNode#elementOrNull(Text)IteratorwithSpliteratorforJsonNode#members(boolean)to utilize size knowledgeIteratorwithSpliteratorforJsonNode#elements(boolean)to utilize size knowledgeStringwithTextin return type ofJsonNode#getDeclarationStringwithTextin return type ofJsonNode#keysStringwithTextin return type ofJsonNode#membersStringwithTextin return type ofJsonNode#members(boolean)StringwithTextfor JSON string and keys of JSON object entries inJsonNode#valueStringwithTextin return type ofJsonValue#keysStringwithTextin return type ofJsonValue#entriesStringwithTextin return type ofJsonValue#forEachJsonValue#pathnow returnsJsonPath(wasString)Validation.Error#pathnow is of typeJsonPath(wasString)JsonPathException#pathnow is of typeJsonPath(wasString)GetListenernowaccepts aJsonPath(wasString)JsonPrimitive#mapNonNull(not needed)Bugfixes
JsonNodeandJsonValue(only write JSON and paths)JsonNode#getthrowsJsonTreeException(wasJsonPathException) when the operation is used on a non-object nodeJsonNode#getOrNullthrowsJsonTreeException(wasJsonPathException) when the operation is used on a non-object nodeJsonNumber#intValuethrowsJsonPathException(wasNullPointerException) for a node defined JSON null (as stated in javadoc)JsonAbstractObject#hasthrowsJsonTreeExceptionwhen called on an undefined parentPerformance
The general direction is to make the memory footprint as small as possible and rather use some more CPU to skip over sections of the input 1-2 extra times. Profiling shows that the low level scanning of the
char[]is very cheap relative to other allocations, exceptions, reflection and alike.Textviews backed by the JSON itself (if possible) avoids a lot of short-livedStringallocationJsonPathas chain avoidsStringandListallocation and O(1) complexity for common opsTextbased avoidsStringallocation and improves common key ops runtime complexityJsonNode#size()of arrays and objects no longer causes indexingendindex in nodes is now a primitive (avoid wrappers for footprint)JsonNode#value()no longer is cached in a field as the computation has become so cheap it is not with spending the memoryJsonVirtualTreenow has anodefield to cache theJsonNodeit represents once it had accessed it (that saves lots of map lookups)hashCode()onJsonPath(as used extensively for node lookup) is now O(1) utilizing sampling of a linear interpolation