blob: b683dffaddcc9b5bfd68efccb7f60724346c340d [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.kie.workbench.common.stunner.sw.marshall.yaml;
import org.kie.j2cl.tools.yaml.mapper.api.YAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.YAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.exception.YAMLDeserializationException;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.StringYAMLDeserializer;
import org.kie.j2cl.tools.yaml.mapper.api.internal.deser.YAMLDeserializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.StringYAMLSerializer;
import org.kie.j2cl.tools.yaml.mapper.api.internal.ser.YAMLSerializationContext;
import org.kie.j2cl.tools.yaml.mapper.api.node.NodeType;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlMapping;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlNode;
import org.kie.j2cl.tools.yaml.mapper.api.node.YamlSequence;
import org.kie.workbench.common.stunner.sw.definition.WorkflowExecTimeout;
import org.kie.workbench.common.stunner.sw.definition.WorkflowExecTimeout_YamlMapperImpl;
public class WorkflowExecTimeoutYamlSerializer implements YAMLDeserializer, YAMLSerializer {
private static final WorkflowExecTimeout_YamlMapperImpl mapper =
WorkflowExecTimeout_YamlMapperImpl.INSTANCE;
private static final StringYAMLSerializer stringYAMLSerializer = new StringYAMLSerializer();
private static final StringYAMLDeserializer stringYAMLDeserializer = new StringYAMLDeserializer();
@Override
public Object deserialize(YamlMapping yaml, String key, YAMLDeserializationContext ctx) throws YAMLDeserializationException {
YamlNode value = yaml.getNode(key);
if (value == null) {
return null;
}
return deserialize(value, ctx);
}
@Override
public Object deserialize(YamlNode node, YAMLDeserializationContext ctx) {
if (node == null) {
return null;
}
if(node.type() == NodeType.SCALAR) {
return stringYAMLDeserializer.deserialize(node, ctx);
} else {
return mapper.getDeserializer().deserialize(node, ctx);
}
}
@Override
public void serialize(YamlMapping writer, String propertyName, Object value, YAMLSerializationContext ctx) {
if (value instanceof String) {
stringYAMLSerializer.serialize(writer, propertyName, (String) value, ctx);
} else if (value instanceof WorkflowExecTimeout) {
mapper.getSerializer().serialize(writer, propertyName, (WorkflowExecTimeout) value, ctx);
}
}
@Override
public void serialize(YamlSequence writer, Object value, YAMLSerializationContext ctx) {
throw new UnsupportedOperationException("Unsupported serialization of " + value.getClass());
}
}