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

Core: add variant builder implementation #11857

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aihuaxu
Copy link
Contributor

@aihuaxu aihuaxu commented Dec 22, 2024

This PR adds the implementation to build a variant for primitive, object and array.

The usage:

  • Build from Json
    VariantBuilder.parseJson(json_string);

  • build a primitive

VariantBuilder builder = new VariantBuilder();
VariantPrimitiveBuilder primBuilder = builder.createPrimitive();
Variant variant = primBuilder.writeNumeric(10).build();

  • build an object
 VariantBuilder builder = new VariantBuilder();
 VariantObjectBuilder objBuilder = builder.startObject();
 objBuilder.writeString("key1", "value1").writeNumeric("key2", 3).endObject();
 Variant variant = builder.build();
  • build an array
 VariantBuilder builder = new VariantBuilder();
 VariantArrayBuilder arrBuilder = builder.createArray();
 arrBuilder.writerNumeric(10).writerNumeric(20).endArray();
 Variant variant = builder.build();

Nested arrays and objects can be supported as well.

Part of: #10392

@github-actions github-actions bot added the core label Dec 22, 2024
@aihuaxu aihuaxu marked this pull request as ready for review December 22, 2024 20:11
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch 5 times, most recently from 10f5064 to f8f8e8f Compare December 24, 2024 03:42
@aihuaxu aihuaxu force-pushed the variant-add-writer-impl branch from f8f8e8f to d806c66 Compare December 24, 2024 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant