@@ -683,45 +683,122 @@ public boolean asBoolean(boolean defaultValue) {
683
683
*/
684
684
685
685
/**
686
+ * Method that may be called to verify that {@code this} node is NOT so-called
687
+ * "missing node": that is, one for which {@link #isMissingNode()} returns {@code true}.
688
+ * If not missing node, {@code this} is returned to allow chaining; otherwise
689
+ * {@link IllegalArgumentException} is thrown.
690
+ *
691
+ * @return {@code this} node to allow chaining
692
+ *
693
+ * @throws IllegalArgumentException if this node is "missing node"
694
+ *
686
695
* @since 2.10
687
696
*/
688
- public <T extends JsonNode > T require () {
697
+ public <T extends JsonNode > T require () throws IllegalArgumentException {
689
698
return _this ();
690
699
}
691
700
692
701
/**
702
+ * Method that may be called to verify that {@code this} node is neither so-called
703
+ * "missing node" (that is, one for which {@link #isMissingNode()} returns {@code true})
704
+ * nor "null node" (one for which {@link #isNull()} returns {@code true}).
705
+ * If non-null non-missing node, {@code this} is returned to allow chaining; otherwise
706
+ * {@link IllegalArgumentException} is thrown.
707
+ *
708
+ * @return {@code this} node to allow chaining
709
+ *
710
+ * @throws IllegalArgumentException if this node is either "missing node" or "null node"
711
+ *
693
712
* @since 2.10
694
713
*/
695
- public <T extends JsonNode > T requireNonNull () {
714
+ public <T extends JsonNode > T requireNonNull () throws IllegalArgumentException {
696
715
return _this ();
697
716
}
698
717
699
718
/**
719
+ * Method is functionally equivalent to
720
+ *{@code
721
+ * path(fieldName).required()
722
+ *}
723
+ * and can be used to check that this node is an {@code ObjectNode} (that is, represents
724
+ * JSON Object value) and has value for specified property with key {@code fieldName}
725
+ * (but note that value may be explicit JSON null value).
726
+ * If this node is Object Node and has value for specified property, {@code this} is returned
727
+ * to allow chaining; otherwise {@link IllegalArgumentException} is thrown.
728
+ *
729
+ * @return {@code this} node to allow chaining
730
+ *
731
+ * @throws IllegalArgumentException if this node is not an Object node or if it does not
732
+ * have value for specified property
733
+ *
700
734
* @since 2.10
701
735
*/
702
- public JsonNode required (String fieldName ) {
736
+ public JsonNode required (String fieldName ) throws IllegalArgumentException {
703
737
return _reportRequiredViolation ("Node of type `%s` has no fields" , getClass ().getName ());
704
738
}
705
739
706
740
/**
741
+ * Method is functionally equivalent to
742
+ *{@code
743
+ * path(index).required()
744
+ *}
745
+ * and can be used to check that this node is an {@code ArrayNode} (that is, represents
746
+ * JSON Array value) and has value for specified {@code index}
747
+ * (but note that value may be explicit JSON null value).
748
+ * If this node is Array Node and has value for specified index, {@code this} is returned
749
+ * to allow chaining; otherwise {@link IllegalArgumentException} is thrown.
750
+ *
751
+ * @return {@code this} node to allow chaining
752
+ *
753
+ * @throws IllegalArgumentException if this node is not an Array node or if it does not
754
+ * have value for specified index
755
+ *
707
756
* @since 2.10
708
757
*/
709
- public JsonNode required (int index ) {
758
+ public JsonNode required (int index ) throws IllegalArgumentException {
710
759
return _reportRequiredViolation ("Node of type `%s` has no indexed values" , getClass ().getName ());
711
760
}
712
761
713
762
/**
763
+ * Method is functionally equivalent to
764
+ *{@code
765
+ * at(pathExpr).required()
766
+ *}
767
+ * and can be used to check that there is an actual value node at specified {@link JsonPointer}
768
+ * starting from {@code this} node
769
+ * (but note that value may be explicit JSON null value).
770
+ * If such value node exists {@code this} is returned
771
+ * to allow chaining; otherwise {@link IllegalArgumentException} is thrown.
772
+ *
773
+ * @return {@code this} node to allow chaining
774
+ *
775
+ * @throws IllegalArgumentException if no value node exists at given {@code JSON Pointer} path
776
+ *
714
777
* @since 2.10
715
778
*/
716
- public JsonNode requiredAt (String pathExpr ) {
779
+ public JsonNode requiredAt (String pathExpr ) throws IllegalArgumentException {
717
780
return requiredAt (JsonPointer .compile (pathExpr ));
718
781
}
719
782
720
783
/**
784
+ * Method is functionally equivalent to
785
+ *{@code
786
+ * at(path).required()
787
+ *}
788
+ * and can be used to check that there is an actual value node at specified {@link JsonPointer}
789
+ * starting from {@code this} node
790
+ * (but note that value may be explicit JSON null value).
791
+ * If such value node exists {@code this} is returned
792
+ * to allow chaining; otherwise {@link IllegalArgumentException} is thrown.
793
+ *
794
+ * @return {@code this} node to allow chaining
795
+ *
796
+ * @throws IllegalArgumentException if no value node exists at given {@code JSON Pointer} path
797
+ *
721
798
* @since 2.10
722
799
*/
723
- public final JsonNode requiredAt (final JsonPointer pathExpr ) {
724
- JsonPointer currentExpr = pathExpr ;
800
+ public final JsonNode requiredAt (final JsonPointer path ) throws IllegalArgumentException {
801
+ JsonPointer currentExpr = path ;
725
802
JsonNode curr = this ;
726
803
727
804
// Note: copied from `at()`
@@ -732,7 +809,7 @@ public final JsonNode requiredAt(final JsonPointer pathExpr) {
732
809
curr = curr ._at (currentExpr );
733
810
if (curr == null ) {
734
811
_reportRequiredViolation ("No node at '%s' (unmatched part: '%s')" ,
735
- pathExpr , currentExpr );
812
+ path , currentExpr );
736
813
}
737
814
currentExpr = currentExpr .tail ();
738
815
}
0 commit comments