Skip to content

Latest commit

 

History

History
128 lines (91 loc) · 2.77 KB

Server Common SDK_JsonUtil.md

File metadata and controls

128 lines (91 loc) · 2.77 KB
puppeteer
pdf image
format displayHeaderFooter landscape scale margin
A4
true
false
0.8
top right bottom left
1.2cm
1cm
1cm
1cm
quality fullPage
100
false

Server Common SDK API - JsonUtil

  • Date: 2024-09-02
  • Version: v1.0.0
Version Date History
v1.0.0 2024-09-02 Initial

Table of Contents

APIs

1. serializeAndSort

Description

Serialize an object into a JSON string, sort the keys alphabetically, and remove all whitespace. This method is used to serialize the original text for signing in OpenDID.

Declaration

public static String serializeAndSort(Object obj) throws JsonProcessingException

Parameters

Name Type Description
obj Object Object to be serialized

Returns

Type Description
String JSON string with sorted keys and no whitespace

Usage

MyObject obj = new MyObject();
String jsonString = JsonUtil.serializeAndSort(obj);

2. serializeToJson

Description

Converts any object to a JSON string.

Declaration

public static String serializeToJson(Object obj) throws JsonProcessingException

Parameters

Name Type Description
obj Object Object to convert

Returns

Type Description
String JSON String

Usage

MyObject obj = new MyObject();
String jsonString = JsonUtil.serializeToJson(obj);

3. deserializeFromJson

Description

Deserializes a JSON string into an object of the specified class type.

Declaration

public static <T> T deserializeFromJson(String jsonString, Class<T> clazz) throws JsonProcessingException

Parameters

Name Type Description
jsonString String JSON string
clazz Class Class type to deserialize

Returns

Type Description
T Deserialized object

Usage

String jsonString = "{"name":"example", "age":30}";
MyObject obj = JsonUtil.deserializeFromJson(jsonString, MyObject.class);