Skip to content

Removing gson and everit dependencies #238

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

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,19 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>[2.13.0,)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.13.0,)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>[2.13.0,)</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.github.erosb</groupId>
<artifactId>everit-json-schema</artifactId>
</dependency>

<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.auth.AuthDefinition;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Auth;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,21 +67,8 @@ public Auth deserialize(JsonParser jp, DeserializationContext ctxt) throws IOExc
} else {
String authFileDef = node.asText();
String authFileSrc = Utils.getResourceFileAsString(authFileDef);
JsonNode authRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (authFileSrc != null && authFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!authFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(authFileSrc, Object.class);

authRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
authRefNode = jsonWriter.readTree(new JSONObject(authFileSrc).toString());
}

JsonNode authRefNode = Utils.getNode(authFileSrc);
JsonNode refAuth = authRefNode.get("auth");
if (refAuth != null) {
for (final JsonNode nodeEle : refAuth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Constants;
import java.io.IOException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -64,21 +61,8 @@ public Constants deserialize(JsonParser jp, DeserializationContext ctxt) throws
String constantsFileDef = node.asText();
constants.setRefValue(constantsFileDef);
String constantsFileSrc = Utils.getResourceFileAsString(constantsFileDef);
JsonNode constantsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (constantsFileSrc != null && constantsFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!constantsFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(constantsFileSrc, Object.class);

constantsRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
constantsRefNode = jsonWriter.readTree(new JSONObject(constantsFileSrc).toString());
}

JsonNode constantsRefNode = Utils.getNode(constantsFileSrc);
JsonNode refConstants = constantsRefNode.get("constants");
if (refConstants != null) {
constantsDefinition = refConstants;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.error.ErrorDefinition;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Errors;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,21 +67,8 @@ public Errors deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
} else {
String errorsFileDef = node.asText();
String errorsFileSrc = Utils.getResourceFileAsString(errorsFileDef);
JsonNode errorsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (errorsFileSrc != null && errorsFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!errorsFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(errorsFileSrc, Object.class);

errorsRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
errorsRefNode = jsonWriter.readTree(new JSONObject(errorsFileSrc).toString());
}

JsonNode errorsRefNode = Utils.getNode(errorsFileSrc);
JsonNode refErrors = errorsRefNode.get("errors");
if (refErrors != null) {
for (final JsonNode nodeEle : refErrors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.events.EventDefinition;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Events;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,21 +67,9 @@ public Events deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
} else {
String eventsFileDef = node.asText();
String eventsFileSrc = Utils.getResourceFileAsString(eventsFileDef);
JsonNode eventsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (eventsFileSrc != null && eventsFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!eventsFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(eventsFileSrc, Object.class);

eventsRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
eventsRefNode = jsonWriter.readTree(new JSONObject(eventsFileSrc).toString());
}

JsonNode eventsRefNode = Utils.getNode(eventsFileSrc);
JsonNode refEvents = eventsRefNode.get("events");
if (refEvents != null) {
for (final JsonNode nodeEle : refEvents) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.functions.FunctionDefinition;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Functions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,20 +67,9 @@ public Functions deserialize(JsonParser jp, DeserializationContext ctxt) throws
String functionsFileDef = node.asText();
String functionsFileSrc = Utils.getResourceFileAsString(functionsFileDef);
JsonNode functionsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (functionsFileSrc != null && functionsFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!functionsFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(functionsFileSrc, Object.class);

functionsRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
functionsRefNode = jsonWriter.readTree(new JSONObject(functionsFileSrc).toString());
}

functionsRefNode = Utils.getNode(functionsFileSrc);
JsonNode refFunctions = functionsRefNode.get("functions");
if (refFunctions != null) {
for (final JsonNode nodeEle : refFunctions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.retry.RetryDefinition;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Retries;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -69,21 +67,8 @@ public Retries deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
} else {
String retriesFileDef = node.asText();
String retriesFileSrc = Utils.getResourceFileAsString(retriesFileDef);
JsonNode retriesRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (retriesFileSrc != null && retriesFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!retriesFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(retriesFileSrc, Object.class);

retriesRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
retriesRefNode = jsonWriter.readTree(new JSONObject(retriesFileSrc).toString());
}

JsonNode retriesRefNode = Utils.getNode(retriesFileSrc);
JsonNode refRetries = retriesRefNode.get("retries");
if (refRetries != null) {
for (final JsonNode nodeEle : refRetries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.serverlessworkflow.api.interfaces.WorkflowPropertySource;
import io.serverlessworkflow.api.utils.Utils;
import io.serverlessworkflow.api.workflow.Secrets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -66,21 +63,9 @@ public Secrets deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
} else {
String secretsFileDef = node.asText();
String secretsFileSrc = Utils.getResourceFileAsString(secretsFileDef);
JsonNode secretsRefNode;
ObjectMapper jsonWriter = new ObjectMapper();
if (secretsFileSrc != null && secretsFileSrc.trim().length() > 0) {
// if its a yaml def convert to json first
if (!secretsFileSrc.trim().startsWith("{")) {
// convert yaml to json to validate
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(secretsFileSrc, Object.class);

secretsRefNode =
jsonWriter.readTree(new JSONObject(jsonWriter.writeValueAsString(obj)).toString());
} else {
secretsRefNode = jsonWriter.readTree(new JSONObject(secretsFileSrc).toString());
}

JsonNode secretsRefNode = Utils.getNode(secretsFileSrc);
JsonNode refSecrets = secretsRefNode.get("secrets");
if (refSecrets != null) {
for (final JsonNode nodeEle : refSecrets) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* 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 io.serverlessworkflow.api.mapper;

import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonObjectMapperFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure i get point of this class. Just maybe have static instance of yaml/json mappers in a util class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This avoid creating a new object mapper instance every time is needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok got it. i think since you return just the basic "new" mapper just define it in static field in some util class no need imo
for separate class. if you want to allow users to set specific configuration for the mappers then having it in some separate class like this maybe makes more sense

Copy link
Collaborator Author

@fjtirado fjtirado Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in a separate class to only initialize the mapper object when it is really used. If you put it into an utils class it will get initialized the firts time you use the utilities class, even in the utility method being used is unrelated (imagine an use that never use yaml format)


private static final ObjectMapper instance = new JsonObjectMapper();

public static final ObjectMapper mapper() {
return instance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020-Present The Serverless Workflow Specification Authors
*
* 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 io.serverlessworkflow.api.mapper;

import com.fasterxml.jackson.databind.ObjectMapper;

public class YamlObjectMapperFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, to avoid creating multiple object mapper instances


private static final ObjectMapper instance = new YamlObjectMapper();

public static final ObjectMapper mapper() {
return instance;
}
}

This file was deleted.

Loading