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

[FEATURE] New factory API to control the type labelKey serialization. #1595

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Dec 21, 2022

  1. [FEATURE] New factory API to control the type labelKey serialization.

    New API `autoSerializeLabel(boolean)` added to allow the factory can be configured with boolean flag to disable automatic serialization of the type label, and it's respective value. Here is how the configuration may look like in the factory builder.
    
    ```java
    PolymorphicJsonAdapterFactory.of(Message.class, "type")
        .withSubtype(Success.class, "success")
        .withSubtype(MessageWithType.class, "customType")
        .autoSerializeLabel(false)) // ← New API!
    ```
    
    This is done for use cases when all known subtypes has serializable type property in the class definition, then it generates double `type` properties when serialized to JSON.
    hossain-khan committed Dec 21, 2022
    Configuration menu
    Copy the full SHA
    713f156 View commit details
    Browse the repository at this point in the history

Commits on Mar 31, 2023

  1. Merge branch 'master' into feature/PolymorphicJsonAdapterFactory-opti…

    …onal-label
    
    # Conflicts:
    #	moshi-adapters/src/main/java/com/squareup/moshi/adapters/PolymorphicJsonAdapterFactory.kt
    hossain-khan committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    154af43 View commit details
    Browse the repository at this point in the history