[
https://issues.apache.org/jira/browse/BEAM-13965?focusedWorklogId=730743&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-730743
]
ASF GitHub Bot logged work on BEAM-13965:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 22/Feb/22 09:57
Start Date: 22/Feb/22 09:57
Worklog Time Spent: 10m
Work Description: mosche opened a new pull request #16913:
URL: https://github.com/apache/beam/pull/16913
Use TypeDeserializer if type information is available to support polymorphic
types.
------------------------
Thank you for your contribution! Follow this checklist to help us
incorporate your contribution quickly and easily:
- [ ] [**Choose
reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and
mention them in a comment (`R: @username`).
- [ ] Format the pull request title like `[BEAM-XXX] Fixes bug in
ApproximateQuantiles`, where you replace `BEAM-XXX` with the appropriate JIRA
issue, if applicable. This will automatically link the pull request to the
issue.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual
Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more
tips on [how to make review process
smoother](https://beam.apache.org/contribute/#make-reviewers-job-easier).
To check the build health, please visit
[https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/validate-runner/README.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more
information about GitHub Actions CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 730743)
Remaining Estimate: 0h
Time Spent: 10m
> Polymorphic types not supported in PipelineOptions
> --------------------------------------------------
>
> Key: BEAM-13965
> URL: https://issues.apache.org/jira/browse/BEAM-13965
> Project: Beam
> Issue Type: Improvement
> Components: sdk-java-core
> Reporter: Moritz Mack
> Assignee: Moritz Mack
> Priority: P2
> Time Spent: 10m
> Remaining Estimate: 0h
>
> I noticed that polymorphic types using @JsonTypeInfo and @JsonSubTypes are
> currently not supported in pipeline options as deserialization fails lacking
> necessary type information. One has to provide a de/serializer and handle
> things manually.
> Looks like the deserialization code path should just follow the serialization
> path.
>
> {noformat}
> diff --git
> a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
>
> b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
> ---
> a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
> (revision 53f5a3c1756509b6fab75d3946a9f95247d02184)
> +++
> b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
> (date 1645114275316)
> @@ -1725,7 +1725,8 @@
> }
> }
>
> - private static JsonDeserializer<Object>
> computeDeserializerForMethod(Method method) {
> + private static Optional<JsonDeserializer<Object>>
> computeCustomDeserializerForMethod(
> + Method method) {
> try {
> BeanProperty prop = createBeanProperty(method);
> AnnotatedMember annotatedMethod = prop.getMember();
> @@ -1736,16 +1737,10 @@
> .getAnnotationIntrospector()
> .findDeserializer(annotatedMethod);
>
> - JsonDeserializer<Object> jsonDeserializer =
> + return Optional.fromNullable(
> DESERIALIZATION_CONTEXT
> .get()
> - .deserializerInstance(annotatedMethod, maybeDeserializerClass);
> -
> - if (jsonDeserializer == null) {
> - jsonDeserializer =
> -
> DESERIALIZATION_CONTEXT.get().findContextualValueDeserializer(prop.getType(),
> prop);
> - }
> - return jsonDeserializer;
> + .deserializerInstance(annotatedMethod,
> maybeDeserializerClass));
> } catch (JsonMappingException e) {
> throw new RuntimeException(e);
> }
> @@ -1771,11 +1766,12 @@
> * JsonDeserialize} the specified deserializer from the annotation is
> returned, otherwise the
> * default is returned.
> */
> - private static JsonDeserializer<Object> getDeserializerForMethod(Method
> method) {
> + private static @Nullable JsonDeserializer<Object>
> getCustomDeserializerForMethod(Method method) {
> return CACHE
> .get()
> .deserializerCache
> - .computeIfAbsent(method,
> PipelineOptionsFactory::computeDeserializerForMethod);
> + .computeIfAbsent(method,
> PipelineOptionsFactory::computeCustomDeserializerForMethod)
> + .orNull();
> }
>
> /**
> @@ -1796,10 +1792,13 @@
> return null;
> }
>
> + JsonDeserializer<Object> jsonDeserializer =
> getCustomDeserializerForMethod(method);
> + if (jsonDeserializer == null) {
> + return DESERIALIZATION_CONTEXT.get().readTreeAsValue(node,
> method.getReturnType());
> + }
> +
> JsonParser parser = new TreeTraversingParser(node, MAPPER);
> parser.nextToken();
> -
> - JsonDeserializer<Object> jsonDeserializer =
> getDeserializerForMethod(method);
> return jsonDeserializer.deserialize(parser,
> DESERIALIZATION_CONTEXT.get());
> }
>
> @@ -2055,7 +2054,8 @@
> private final Map<Set<Class<? extends PipelineOptions>>,
> Registration<?>> combinedCache =
> Maps.newConcurrentMap();
>
> - private final Map<Method, JsonDeserializer<Object>> deserializerCache =
> Maps.newConcurrentMap();
> + private final Map<Method, Optional<JsonDeserializer<Object>>>
> deserializerCache =
> + Maps.newConcurrentMap();
>
> private final Map<Method, Optional<JsonSerializer<Object>>>
> serializerCache =
> Maps.newConcurrentMap();
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)