44import com .fasterxml .jackson .core .JsonProcessingException ;
55import com .fasterxml .jackson .databind .DeserializationFeature ;
66import com .fasterxml .jackson .databind .MapperFeature ;
7- import com .fasterxml .jackson .databind .ObjectMapper ;
87import com .fasterxml .jackson .databind .SerializationFeature ;
98import com .fasterxml .jackson .databind .json .JsonMapper ;
109import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
1110import com .godiddy .api .client .ApiClient ;
1211import com .godiddy .api .client .ApiResponse ;
1312import com .godiddy .api .client .openapi .api .*;
1413import com .godiddy .api .client .openapi .model .*;
15- import com .godiddy .cli .clistorage .clistate .CLIState ;
1614import uniregistrar .openapi .RFC3339DateFormat ;
1715
1816import java .io .*;
2321import java .nio .ByteBuffer ;
2422import java .util .List ;
2523import java .util .Map ;
26- import java .util .Objects ;
2724import java .util .concurrent .Callable ;
2825import java .util .concurrent .Flow ;
2926import java .util .function .Consumer ;
3229
3330public class Api {
3431
35- private static final ObjectMapper objectMapper = JsonMapper .builder ()
32+ private static final JsonMapper jsonMapper = JsonMapper .builder ()
3633 .serializationInclusion (JsonInclude .Include .NON_NULL )
3734 .disable (MapperFeature .ALLOW_COERCION_OF_SCALARS )
3835 .enable (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES )
@@ -143,14 +140,14 @@ public static <T> T execute(Callable<ApiResponse<T>> supplier) throws Exception
143140
144141 public static void writeJson (File file , Object object , boolean pretty ) throws IOException {
145142 if (pretty ) {
146- objectMapper .writerWithDefaultPrettyPrinter ().writeValue (file , object );
143+ jsonMapper .writerWithDefaultPrettyPrinter ().writeValue (file , object );
147144 } else {
148- objectMapper .writeValue (file , object );
145+ jsonMapper .writeValue (file , object );
149146 }
150147 }
151148
152149 public static Object readJson (File file , Class cl ) throws IOException {
153- return objectMapper .readValue (file , cl );
150+ return jsonMapper .readValue (file , cl );
154151 }
155152
156153 public static Map <String , Object > fromJson (String json ) {
@@ -159,14 +156,22 @@ public static Map<String, Object> fromJson(String json) {
159156
160157 public static <T > T fromJson (String json , Class <T > cl ) {
161158 try {
162- return objectMapper .readValue (json , cl );
159+ return jsonMapper .readValue (json , cl );
163160 } catch (JsonProcessingException ex ) {
164161 throw new IllegalArgumentException (ex );
165162 }
166163 }
167164
168165 public static <T > T convert (Object object , Class <T > cl ) {
169- return objectMapper .convertValue (object , cl );
166+ return jsonMapper .convertValue (object , cl );
167+ }
168+
169+ public static String string (Object object ) {
170+ try {
171+ return jsonMapper .writeValueAsString (object );
172+ } catch (JsonProcessingException ex ) {
173+ throw new IllegalArgumentException (ex .getMessage (), ex );
174+ }
170175 }
171176
172177 public static void print (Object object ) {
@@ -193,11 +198,11 @@ private static void print(Object object, String interpretedString, Formatting.Va
193198 if (formatting == Formatting .Value .interpreted ) {
194199 string = interpretedString == null ? "(null)" : interpretedString ;
195200 } else if (formatting == Formatting .Value .pretty ) {
196- if (object instanceof String ) object = objectMapper .readValue ((String ) object , Object .class );
197- string = object == null ? "(null)" : objectMapper .writerWithDefaultPrettyPrinter ().writeValueAsString (object );
201+ if (object instanceof String ) object = jsonMapper .readValue ((String ) object , Object .class );
202+ string = object == null ? "(null)" : jsonMapper .writerWithDefaultPrettyPrinter ().writeValueAsString (object );
198203 } else if (formatting == Formatting .Value .flat ) {
199- if (object instanceof String ) object = objectMapper .readValue ((String ) object , Object .class );
200- string = object == null ? "(null)" : objectMapper .writeValueAsString (object );
204+ if (object instanceof String ) object = jsonMapper .readValue ((String ) object , Object .class );
205+ string = object == null ? "(null)" : jsonMapper .writeValueAsString (object );
201206 } else if (formatting == Formatting .Value .raw ) {
202207 string = object == null ? "(null)" : object .toString ();
203208 } else if (formatting == Formatting .Value .off ) {
@@ -235,7 +240,7 @@ public static void printHeaders(HttpHeaders httpHeaders, String prefix) {
235240
236241 private static String constructInterpretedString (RegistrarRequest registrarRequest ) {
237242 String name = registrarRequest .getClass ().getSimpleName ();
238- String jobId = registrarRequest .getJobId ();
243+ String jobId = "" + ( registrarRequest .getJobId () == null ? "" : registrarRequest . getJobId (). getString () );
239244 String didDocumentVerificationMethods = "" + (! (registrarRequest instanceof CreateRequest createRequest ) ? 0 : createRequest .getDidDocument () == null ? 0 : createRequest .getDidDocument ().getVerificationMethod () == null ? 0 : createRequest .getDidDocument ().getVerificationMethod ().size ()) + " DID document verification methods" ;
240245 String secretVerificationMethods = "" + (registrarRequest .getSecret () == null ? 0 : registrarRequest .getSecret ().getVerificationMethod () == null ? 0 : registrarRequest .getSecret ().getVerificationMethod ().size ()) + " secret verification methods" ;
241246 String signingResponses = "" + (registrarRequest .getSecret () == null ? 0 : registrarRequest .getSecret ().getSigningResponse () == null ? 0 : registrarRequest .getSecret ().getSigningResponse ().size ()) + " signing responses" ;
@@ -257,7 +262,7 @@ private static String constructInterpretedString(RegistrarRequest registrarReque
257262
258263 private static String constructInterpretedString (RegistrarState registrarState ) {
259264 String name = registrarState .getClass ().getSimpleName ();
260- String jobId = registrarState .getJobId ();
265+ String jobId = "" + ( registrarState .getJobId () == null ? "" : string ( registrarState . getJobId ()) );
261266 String state = registrarState .getDidState () == null ? "null" : registrarState .getDidState ().getState ();
262267 String action = ! (registrarState .getDidState () instanceof DidStateAction didStateAction ) ? "null" : didStateAction .getAction () == null ? "null" : didStateAction .getAction ();
263268 String did = registrarState .getDidState () == null ? "null" : registrarState .getDidState ().getDid ();
@@ -288,7 +293,7 @@ private static String constructInterpretedString(RegistrarState registrarState)
288293
289294 private static String constructInterpretedString (RegistrarResourceState registrarResourceState ) {
290295 String name = registrarResourceState .getClass ().getSimpleName ();
291- String jobId = registrarResourceState .getJobId ();
296+ String jobId = "" + ( registrarResourceState .getJobId () == null ? "" : registrarResourceState . getJobId (). getString () );
292297 String state = registrarResourceState .getDidUrlState () == null ? "null" : registrarResourceState .getDidUrlState ().getState ();
293298 String action = ! (registrarResourceState .getDidUrlState () instanceof DidUrlStateAction didUrlStateAction ) ? "null" : didUrlStateAction .getAction () == null ? "null" : didUrlStateAction .getAction ();
294299 String didUrl = registrarResourceState .getDidUrlState () == null ? "null" : registrarResourceState .getDidUrlState ().getDidUrl ();
0 commit comments