File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
api/src/main/java/jakarta/json Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -517,4 +517,15 @@ public static String decodePointer(String escaped) {
517517 return escaped .replace ("~1" , "/" ).replace ("~0" , "~" );
518518 }
519519
520+ /**
521+ * Creates a JsonNumber.
522+ *
523+ * @param value a JSON number
524+ * @return the JsonNumber for the number
525+ *
526+ * @since 2.1
527+ */
528+ public static JsonNumber createValue (Number value ) {
529+ return JsonProvider .provider ().createValue (value );
530+ }
520531}
Original file line number Diff line number Diff line change @@ -477,4 +477,32 @@ public JsonNumber createValue(BigDecimal value) {
477477 public JsonNumber createValue (BigInteger value ) {
478478 throw new UnsupportedOperationException ();
479479 }
480+
481+ /**
482+ * Creates a JsonNumber.
483+ *
484+ * When it is not implemented it checks the type and delegates
485+ * to an existing method that already handles that type. It throws
486+ * UnsupportedOperationException in case the type is not known.
487+ *
488+ * @param number a JSON number
489+ * @return the JsonNumber for the number
490+ *
491+ * @since 2.1
492+ */
493+ public JsonNumber createValue (Number number ) {
494+ if (number instanceof Integer ) {
495+ return createValue (number .intValue ());
496+ } else if (number instanceof Long ) {
497+ return createValue (number .longValue ());
498+ } else if (number instanceof Double ) {
499+ return createValue (number .doubleValue ());
500+ } else if (number instanceof BigInteger ) {
501+ return createValue ((BigInteger ) number );
502+ } else if (number instanceof BigDecimal ) {
503+ return createValue ((BigDecimal ) number );
504+ } else {
505+ throw new UnsupportedOperationException (number + " type is not known" );
506+ }
507+ }
480508}
You can’t perform that action at this time.
0 commit comments