Skip to content
New issue

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

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

Already on GitHub? # to your account

How to de/serialize an instance from/to Json/Yaml with dynamically typed attribute #15

Open
davideuler opened this issue Apr 29, 2022 · 0 comments

Comments

@davideuler
Copy link
Owner

public class FlowExecutor {

    private String flowName;

    @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
    private List<PreProcessor> preProcessors;

    @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
    private List<PostProcessor> postAnalyzers;

}

public interface PreProcessor {
    void process(Request request, Context context);
}

YAMLFactory f = new YAMLFactory();
f.disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
ObjectMapper mapper = new ObjectMapper(f);
String config = mapper.writeValueAsString(executor);

see:
https://stackoverflow.com/questions/55008706/how-to-de-serialize-an-instance-with-dynamically-typed-attribute
https://www.baeldung.com/jackson-inheritance

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant