Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#466 Convert JSON object to CBORMetadataMap and JSON Array to CBORMetadataList / New methods in MetadataBuilder #467

Merged
merged 5 commits into from
Nov 19, 2024

Conversation

satran004
Copy link
Member

@satran004 satran004 commented Oct 24, 2024

Current State:
Currently, we have low-level classes such as CBORMetadata, CBORMetadataMap, etc., and a few helper classes like MetadataToJsonNoSchemaConverter and JsonNoSchemaToMetadataConverter 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-level CBORMetadata 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 of Metadata.
  • createMap() – Creates an instance of MetadataMap.
  • createList() – Creates an instance of MetadataList.

Deserialization:

  • deserialize(byte[] cborBytes) – Deserializes CBOR byte arrays into a Metadata object.

JSON to Metadata Conversion Methods:

  • metadataFromJson(String json) – Converts a JSON string to a Metadata object.
  • metadataFromJsonBody(BigInteger label, String jsonBody) – Converts a JSON string into a Metadata object with a specified label, handling both JSON objects and arrays.
  • metadataMapFromJsonBody(String jsonBody) – Parses a JSON body string to create a MetadataMap instance.
  • metadataListFromJsonBody(String jsonBody) – Parses a JSON body string to create a MetadataList instance.

Metadata to JSON Conversion Methods:

  • toJson(Metadata metadata) – Converts a Metadata object to its JSON string representation.
  • toJson(byte[] serializedCbor) – Converts a CBOR byte array to a JSON string.

@satran004 satran004 marked this pull request as draft October 24, 2024 05:40
@satran004 satran004 changed the title #466 Convert JSON object to CborMetadataMap and JSON Array to CboMetadataList (DRAFT) #466 Convert JSON object to CBORMetadataMap and JSON Array to CBORMetadataList (DRAFT) Oct 24, 2024
Added several new unit tests for MetadataBuilder and improved the handling of byte strings in the metadata converter. Also included multiple new test JSON files to cover different metadata scenarios.
@satran004 satran004 changed the title #466 Convert JSON object to CBORMetadataMap and JSON Array to CBORMetadataList (DRAFT) #466 Convert JSON object to CBORMetadataMap and JSON Array to CBORMetadataList / New methods in MetadataBuilder Nov 10, 2024
@satran004 satran004 marked this pull request as ready for review November 10, 2024 06:24
Copy link

@satran004 satran004 merged commit 436b396 into master Nov 19, 2024
5 checks passed
@satran004 satran004 deleted the fix_466 branch November 19, 2024 03:25
edridudi pushed a commit to adabox-aio/cardano-client-lib that referenced this pull request Feb 27, 2025
… CBORMetadataList / New methods in MetadataBuilder (bloxbean#467)

* bloxbean#466 Make json object --> CBOR Map and json array --> CBOR Array methods public and handle null value

* bloxbean#466 fixed tests

* bloxbean#466 Handle BigInteger encoded as ByteString

* Add unit tests and improve metadata JSON handling

Added several new unit tests for MetadataBuilder and improved the handling of byte strings in the metadata converter. Also included multiple new test JSON files to cover different metadata scenarios.

* To fix Sonarcloud warnings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants