-
Notifications
You must be signed in to change notification settings - Fork 51
feat(QTDI-2215):deserialize a json to a Schema instance #1145
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
base: master
Are you sure you want to change the base?
Changes from all commits
d1d4568
53bb857
f887895
46bd816
d4bf4b9
fec3895
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,4 +76,4 @@ | |
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,107 @@ | ||||||||||||||||||
| /** | ||||||||||||||||||
| * Copyright (C) 2006-2025 Talend Inc. - www.talend.com | ||||||||||||||||||
| * | ||||||||||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||||||||||
| * You may obtain a copy of the License at | ||||||||||||||||||
| * | ||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||
| * | ||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||
| * See the License for the specific language governing permissions and | ||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||
| */ | ||||||||||||||||||
| package org.talend.sdk.component.server.front.model; | ||||||||||||||||||
|
|
||||||||||||||||||
| import java.beans.ConstructorProperties; | ||||||||||||||||||
| import java.util.LinkedHashMap; | ||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||
|
|
||||||||||||||||||
| import lombok.Data; | ||||||||||||||||||
|
|
||||||||||||||||||
| @Data | ||||||||||||||||||
| public final class Entry { | ||||||||||||||||||
|
|
||||||||||||||||||
| private final String name; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final String rawName; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final Schema.Type type; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final boolean nullable; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final boolean metadata; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final boolean errorCapable; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final boolean valid; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final Schema elementSchema; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final String comment; | ||||||||||||||||||
|
|
||||||||||||||||||
| private final Map<String, String> props = new LinkedHashMap<>(0); | ||||||||||||||||||
|
|
||||||||||||||||||
| private final Object defaultValue; | ||||||||||||||||||
|
|
||||||||||||||||||
| @ConstructorProperties({ "name", "rawName", "type", "nullable", "metadata", "errorCapable", | ||||||||||||||||||
| "valid", "elementSchema", "comment", "props", "defaultValue" }) | ||||||||||||||||||
| // Checkstyle off to let have 11 parameters to this constructor (normally 10 max) | ||||||||||||||||||
| // CHECKSTYLE:OFF | ||||||||||||||||||
| public Entry( | ||||||||||||||||||
|
Check warning on line 53 in component-server-parent/component-server-model/src/main/java/org/talend/sdk/component/server/front/model/Entry.java
|
||||||||||||||||||
| final String name, | ||||||||||||||||||
| final String rawName, | ||||||||||||||||||
| final Schema.Type type, | ||||||||||||||||||
| final boolean nullable, | ||||||||||||||||||
| final boolean metadata, | ||||||||||||||||||
| final boolean errorCapable, | ||||||||||||||||||
| final boolean valid, | ||||||||||||||||||
| final Schema elementSchema, | ||||||||||||||||||
| final String comment, | ||||||||||||||||||
| final Map<String, String> props, | ||||||||||||||||||
| final Object defaultValue) { | ||||||||||||||||||
| // CHECKSTYLE:ON | ||||||||||||||||||
| this.name = name; | ||||||||||||||||||
| this.rawName = rawName; | ||||||||||||||||||
| this.type = type; | ||||||||||||||||||
| this.nullable = nullable; | ||||||||||||||||||
| this.metadata = metadata; | ||||||||||||||||||
| this.errorCapable = errorCapable; | ||||||||||||||||||
| this.valid = valid; | ||||||||||||||||||
| this.elementSchema = elementSchema; | ||||||||||||||||||
| this.comment = comment; | ||||||||||||||||||
| this.props.putAll(props); | ||||||||||||||||||
| this.defaultValue = defaultValue; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private Object getInternalDefaultValue() { | ||||||||||||||||||
| return defaultValue; | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+79
to
+81
|
||||||||||||||||||
|
|
||||||||||||||||||
| @SuppressWarnings("unchecked") | ||||||||||||||||||
| public <T> T getDefaultValue() { | ||||||||||||||||||
| if (defaultValue == null) { | ||||||||||||||||||
| return null; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return switch (this.getType()) { | ||||||||||||||||||
| case INT -> (T) ((Integer) ((Number) this.getInternalDefaultValue()).intValue()); | ||||||||||||||||||
| case LONG -> (T) ((Long) ((Number) this.getInternalDefaultValue()).longValue()); | ||||||||||||||||||
| case FLOAT -> (T) ((Float) ((Number) this.getInternalDefaultValue()).floatValue()); | ||||||||||||||||||
| case DOUBLE -> (T) ((Double) ((Number) this.getInternalDefaultValue()).doubleValue()); | ||||||||||||||||||
| default -> (T) this.getInternalDefaultValue(); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| public String getOriginalFieldName() { | ||||||||||||||||||
| return rawName != null ? rawName : name; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
||||||||||||||||||
| /** | |
| * Returns the property value associated with the given key. | |
| * | |
| * @param key the property key | |
| * @return the property value, or {@code null} if there is no mapping for the given key | |
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Copyright (C) 2006-2025 Talend Inc. - www.talend.com | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.talend.sdk.component.server.front.model; | ||
|
|
||
| import java.beans.ConstructorProperties; | ||
| import java.math.BigDecimal; | ||
| import java.time.temporal.Temporal; | ||
| import java.util.Collection; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public final class Schema { | ||
|
|
||
| private final Type type; | ||
|
|
||
| private final Schema elementSchema; | ||
|
|
||
| private final List<Entry> entries; | ||
|
|
||
| private final List<Entry> metadata; | ||
|
|
||
| private final Map<String, String> props; | ||
|
|
||
| @ConstructorProperties({ "type", "elementSchema", "entries", "metadata", "props" }) | ||
| public Schema( | ||
| final Type type, | ||
| final Schema elementSchema, | ||
| final List<Entry> entries, | ||
| final List<Entry> metadata, | ||
| final Map<String, String> props) { | ||
| this.type = type; | ||
| this.elementSchema = elementSchema; | ||
| this.entries = entries; | ||
| this.metadata = metadata; | ||
| this.props = props; | ||
| } | ||
|
|
||
| public String getProp(final String key) { | ||
| return this.props.get(key); | ||
|
Comment on lines
+55
to
+56
|
||
| } | ||
|
|
||
| public enum Type { | ||
|
|
||
| RECORD(new Class<?>[] { Record.class }), | ||
| ARRAY(new Class<?>[] { Collection.class }), | ||
| STRING(new Class<?>[] { String.class, Object.class }), | ||
| BYTES(new Class<?>[] { byte[].class, Byte[].class }), | ||
| INT(new Class<?>[] { Integer.class }), | ||
| LONG(new Class<?>[] { Long.class }), | ||
| FLOAT(new Class<?>[] { Float.class }), | ||
| DOUBLE(new Class<?>[] { Double.class }), | ||
| BOOLEAN(new Class<?>[] { Boolean.class }), | ||
| DATETIME(new Class<?>[] { Long.class, Date.class, Temporal.class }), | ||
| DECIMAL(new Class<?>[] { BigDecimal.class }); | ||
|
|
||
| /** | ||
| * All compatibles Java classes | ||
| */ | ||
| private final Class<?>[] classes; | ||
|
|
||
| Type(final Class<?>[] classes) { | ||
| this.classes = classes; | ||
| } | ||
|
|
||
| /** | ||
| * Check if input can be affected to an entry of this type. | ||
| * | ||
| * @param input : object. | ||
| * | ||
| * @return true if input is null or ok. | ||
| */ | ||
| public boolean isCompatible(final Object input) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this method, it is not used. |
||
| if (input == null) { | ||
| return true; | ||
| } | ||
| for (final Class<?> clazz : classes) { | ||
| if (clazz.isInstance(input)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,11 +63,6 @@ | |
| <artifactId>component-runtime-design-extension</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.talend.sdk.component</groupId> | ||
| <artifactId>component-server-api</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.talend.sdk.component</groupId> | ||
| <artifactId>vault-client</artifactId> | ||
|
|
@@ -191,13 +186,23 @@ | |
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.talend.sdk.component</groupId> | ||
| <artifactId>component-server-api</artifactId> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it has been moved ? |
||
| <version>${project.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.talend.sdk.component</groupId> | ||
| <artifactId>component-form-core</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this dependency |
||
| <artifactId>jackson-databind</artifactId> | ||
| <version>${jackson.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
|
|
@@ -493,4 +498,4 @@ | |
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> | ||
| </project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor will throw NullPointerException if the props parameter is null. Add a null check before calling putAll, e.g.,
if (props != null) { this.props.putAll(props); }