You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2019/06/27 20:15:18 UTC

[plc4x] 02/04: - Added Jackson annotations to enable serializing and parsing with Jackson.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit ffb28aec2bd84ea2b817dc887badbf4b7b71b13d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Jun 27 22:11:04 2019 +0200

    - Added Jackson annotations to enable serializing and parsing with Jackson.
---
 .../src/main/resources/templates/java/pojo-template.ftlh           | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
index 75279ff..33abe95 100644
--- a/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
+++ b/build-utils/language-java/src/main/resources/templates/java/pojo-template.ftlh
@@ -38,8 +38,10 @@ ${packageName?replace(".", "/")}/${typeName}.java
 
 package ${packageName};
 
+import com.fasterxml.jackson.annotation.*;
 import org.apache.plc4x.java.utils.SizeAware;
 
+<#if type.abstract>@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "className")</#if>
 public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??> extends ${type.parentType.name}</#if> implements SizeAware {
 
 <#if helper.isDiscriminatedType(type)>
@@ -66,7 +68,8 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 </#list>
 </#if>
 
-    public ${typeName}(<#list type.getAllPropertyFields() as field>${helper.getLanguageTypeNameForField(field)}<#if field.lengthType??>[]</#if> ${field.name}<#sep>, </#sep></#list>) {
+    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
+    public ${typeName}(<#list type.getAllPropertyFields() as field>@JsonProperty("${field.name}") ${helper.getLanguageTypeNameForField(field)}<#if field.lengthType??>[]</#if> ${field.name}<#sep>, </#sep></#list>) {
 <#if type.getParentPropertyFields()?has_content>
         super(<#list type.getParentPropertyFields() as field>${field.name}<#sep>, </#sep></#list>);
 </#if>
@@ -80,6 +83,7 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 </#if>
 <#if helper.isDiscriminatedType(type)>
 
+    @JsonIgnore
     public Object[] getDiscriminatorValues() {
         return DISCRIMINATOR_VALUES;
     }
@@ -92,6 +96,7 @@ public<#if type.abstract> abstract</#if> class ${typeName}<#if type.parentType??
 
 </#list>
     @Override
+    @JsonIgnore
     public int getLengthInBytes() {
         int lengthInBits = <#if type.parentType??>super.getLengthInBytes() * 8<#else>0</#if>;
 <#list type.fields as field>