Skip to content

Commit 40e51dd

Browse files
committed
[Fix_#449] Checking pattern
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent ac17c47 commit 40e51dd

File tree

10 files changed

+362
-56
lines changed

10 files changed

+362
-56
lines changed

api/src/main/java/io/serverlessworkflow/api/ObjectMapperFactory.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
2222
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator.Feature;
2323
import io.serverlessworkflow.serialization.BeanDeserializerModifierWithValidation;
24+
import io.serverlessworkflow.serialization.URIDeserializer;
25+
import io.serverlessworkflow.serialization.URISerializer;
26+
import java.net.URI;
2427

2528
class ObjectMapperFactory {
2629

@@ -39,7 +42,10 @@ public static final ObjectMapper yamlMapper() {
3942

4043
private static ObjectMapper configure(ObjectMapper mapper) {
4144
SimpleModule validationModule = new SimpleModule();
45+
validationModule.addDeserializer(URI.class, new URIDeserializer());
46+
validationModule.addSerializer(URI.class, new URISerializer());
4247
validationModule.setDeserializerModifier(new BeanDeserializerModifierWithValidation());
48+
4349
return mapper
4450
.configure(SerializationFeature.INDENT_OUTPUT, true)
4551
.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.serialization;
17+
18+
import com.fasterxml.jackson.core.JsonParser;
19+
import com.fasterxml.jackson.databind.DeserializationContext;
20+
import com.fasterxml.jackson.databind.JsonDeserializer;
21+
import com.fasterxml.jackson.databind.JsonMappingException;
22+
import java.io.IOException;
23+
import java.net.URI;
24+
import java.net.URISyntaxException;
25+
26+
public class URIDeserializer extends JsonDeserializer<URI> {
27+
@Override
28+
public URI deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
29+
try {
30+
String uriStr = p.getValueAsString();
31+
if (uriStr == null) {
32+
throw new JsonMappingException(p, "URI is not an string");
33+
}
34+
return new URI(uriStr);
35+
} catch (URISyntaxException ex) {
36+
throw new JsonMappingException(p, ex.getMessage());
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.serialization;
17+
18+
import com.fasterxml.jackson.core.JsonGenerator;
19+
import com.fasterxml.jackson.databind.JsonSerializer;
20+
import com.fasterxml.jackson.databind.SerializerProvider;
21+
import java.io.IOException;
22+
import java.net.URI;
23+
24+
public class URISerializer extends JsonSerializer<URI> {
25+
26+
@Override
27+
public void serialize(URI value, JsonGenerator gen, SerializerProvider serializers)
28+
throws IOException {
29+
gen.writeString(value.toString());
30+
}
31+
}

0 commit comments

Comments
 (0)