...
Jakarta and Spring do no support json Type, but we can use Converters to convert DocToscaServiceTemplate to a Json String.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
@Converter(autoApply = true) public class StringToServiceTemplateConverter implements AttributeConverter<DocToscaServiceTemplate, String> { private static final Coder coder = new StandardCoder(); @Override public String convertToDatabaseColumn(DocToscaServiceTemplate serviceTemplate) { try { return serviceTemplate == null ? null : coder.encode(serviceTemplate); } catch (CoderException e) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); } } @Override public DocToscaServiceTemplate convertToEntityAttribute(String dbData) { if (dbData == null) { return new DocToscaServiceTemplate(); } try { return coder.decode(dbData, DocToscaServiceTemplate.class); } catch (CoderException e) { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); } } } |
Note: Serialization and deserialization in Json is already used in policy-model (Un example could be found here [JpaToscaPolicy.java]). @Converter is just an elegant way to do the same thing.
ToscaServiceTemplate Table
...