|
| 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.api.deserializers; |
| 17 | + |
| 18 | +import com.fasterxml.jackson.core.JsonParser; |
| 19 | +import com.fasterxml.jackson.databind.DeserializationContext; |
| 20 | +import com.fasterxml.jackson.databind.JsonNode; |
| 21 | +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; |
| 22 | +import io.serverlessworkflow.api.interfaces.WorkflowPropertySource; |
| 23 | +import io.serverlessworkflow.api.timeouts.StateExecTimeout; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | + |
| 27 | +public class StateExecTimeoutDeserializer extends StdDeserializer<StateExecTimeout> { |
| 28 | + |
| 29 | + private static final long serialVersionUID = 510l; |
| 30 | + |
| 31 | + @SuppressWarnings("unused") |
| 32 | + private WorkflowPropertySource context; |
| 33 | + |
| 34 | + public StateExecTimeoutDeserializer() { |
| 35 | + this(StateExecTimeout.class); |
| 36 | + } |
| 37 | + |
| 38 | + public StateExecTimeoutDeserializer(Class<?> vc) { |
| 39 | + super(vc); |
| 40 | + } |
| 41 | + |
| 42 | + public StateExecTimeoutDeserializer(WorkflowPropertySource context) { |
| 43 | + this(StateExecTimeout.class); |
| 44 | + this.context = context; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public StateExecTimeout deserialize(JsonParser jp, |
| 49 | + DeserializationContext ctxt) throws IOException { |
| 50 | + |
| 51 | + JsonNode node = jp.getCodec().readTree(jp); |
| 52 | + |
| 53 | + StateExecTimeout stateExecTimeout = new StateExecTimeout(); |
| 54 | + |
| 55 | + if (!node.isObject()) { |
| 56 | + stateExecTimeout.setTotal(node.asText()); |
| 57 | + stateExecTimeout.setSingle(null); |
| 58 | + return stateExecTimeout; |
| 59 | + } else { |
| 60 | + if (node.get("single") != null) { |
| 61 | + stateExecTimeout.setSingle(node.get("single").asText()); |
| 62 | + } |
| 63 | + |
| 64 | + if (node.get("total") != null) { |
| 65 | + stateExecTimeout.setTotal(node.get("total").asText()); |
| 66 | + } |
| 67 | + |
| 68 | + return stateExecTimeout; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments