#466 Convert JSON object to CBORMetadataMap and JSON Array to CBORMetadataList / New methods in MetadataBuilder #467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Current State:
Currently, we have low-level classes such as
CBORMetadata
,CBORMetadataMap
, etc., and a few helper classes likeMetadataToJsonNoSchemaConverter
andJsonNoSchemaToMetadataConverter
for creating metadata or converting metadata to JSON. This sometimes creates confusion regarding how to work with metadata.Although we have a relatively new builder class,
MetadataBuilder
, with static helper methods for creating metadata without using low-levelCBORMetadata
APIs, it lacks the necessary conversion methods directly from or to JSON.Summary of Changes:
This PR introduces new helper methods to
MetadataBuilder
to simplify the process of metadata creation and conversion. In most cases, the use of existing low-level APIs will no longer be necessary.New Methods in
MetadataBuilder
Metadata Creation Methods:
createMetadata()
– Creates an instance ofMetadata
.createMap()
– Creates an instance ofMetadataMap
.createList()
– Creates an instance ofMetadataList
.Deserialization:
deserialize(byte[] cborBytes)
– Deserializes CBOR byte arrays into aMetadata
object.JSON to Metadata Conversion Methods:
metadataFromJson(String json)
– Converts a JSON string to aMetadata
object.metadataFromJsonBody(BigInteger label, String jsonBody)
– Converts a JSON string into aMetadata
object with a specified label, handling both JSON objects and arrays.metadataMapFromJsonBody(String jsonBody)
– Parses a JSON body string to create aMetadataMap
instance.metadataListFromJsonBody(String jsonBody)
– Parses a JSON body string to create aMetadataList
instance.Metadata to JSON Conversion Methods:
toJson(Metadata metadata)
– Converts aMetadata
object to its JSON string representation.toJson(byte[] serializedCbor)
– Converts a CBOR byte array to a JSON string.