11package dev .openfeature .javasdk ;
22
3- import java .time .ZonedDateTime ;
3+ import java .time .Instant ;
44import java .util .List ;
55
66import lombok .EqualsAndHashCode ;
77import lombok .ToString ;
88
99/**
10- * Values serve as a return type for provider objects .
10+ * Values serve as a generic return type for structure data from providers .
1111 * Providers may deal in JSON, protobuf, XML or some other data-interchange format.
1212 * This intermediate representation provides a good medium of exchange.
1313 */
@@ -19,7 +19,27 @@ public class Value {
1919 private final Object innerObject ;
2020
2121 public Value () {
22- this .innerObject = null ;
22+ this .innerObject = null ;
23+ }
24+
25+ /**
26+ * Construct a new Value with an Object.
27+ * @param value to be wrapped.
28+ * @throws InstantiationException if value is not a valid type
29+ * (boolean, string, int, double, list, structure, instant)
30+ */
31+ public Value (Object value ) throws InstantiationException {
32+ // integer is a special case, convert those.
33+ this .innerObject = value instanceof Integer ? ((Integer )value ).doubleValue () : value ;
34+ if (!this .isNull ()
35+ && !this .isBoolean ()
36+ && !this .isString ()
37+ && !this .isNumber ()
38+ && !this .isStructure ()
39+ && !this .isList ()
40+ && !this .isInstant ()) {
41+ throw new InstantiationException ("Invalid value type: " + value .getClass ());
42+ }
2343 }
2444
2545 public Value (Value value ) {
@@ -50,7 +70,7 @@ public Value(List<Value> value) {
5070 this .innerObject = value ;
5171 }
5272
53- public Value (ZonedDateTime value ) {
73+ public Value (Instant value ) {
5474 this .innerObject = value ;
5575 }
5676
@@ -109,12 +129,12 @@ public boolean isList() {
109129 }
110130
111131 /**
112- * Check if this Value represents a ZonedDateTime .
132+ * Check if this Value represents an Instant .
113133 *
114134 * @return boolean
115135 */
116- public boolean isZonedDateTime () {
117- return this .innerObject instanceof ZonedDateTime ;
136+ public boolean isInstant () {
137+ return this .innerObject instanceof Instant ;
118138 }
119139
120140 /**
@@ -131,6 +151,15 @@ public Boolean asBoolean() {
131151 return null ;
132152 }
133153
154+ /**
155+ * Retrieve the underlying object.
156+ *
157+ * @return Object
158+ */
159+ public Object asObject () {
160+ return this .innerObject ;
161+ }
162+
134163 /**
135164 * Retrieve the underlying String value, or null.
136165 *
@@ -194,13 +223,13 @@ public List<Value> asList() {
194223 }
195224
196225 /**
197- * Retrieve the underlying ZonedDateTime value, or null.
226+ * Retrieve the underlying Instant value, or null.
198227 *
199- * @return ZonedDateTime
228+ * @return Instant
200229 */
201- public ZonedDateTime asZonedDateTime () {
202- if (this .isZonedDateTime ()) {
203- return (ZonedDateTime )this .innerObject ;
230+ public Instant asInstant () {
231+ if (this .isInstant ()) {
232+ return (Instant )this .innerObject ;
204233 }
205234 return null ;
206235 }
0 commit comments