在对象内部创建相同类型的实体对象

huangapple 未分类评论66阅读模式
英文:

Create Entity for Objects of same Type inside an Object

问题

我想使用Lombok表示一个复杂的JSON对象:

  1. {
  2. "property1": {
  3. "type": "boolean",
  4. "value": true,
  5. "valueInfo": {
  6. "info": "Hello"
  7. }
  8. },
  9. "property2": {
  10. "type": "string",
  11. "value": "string234",
  12. "valueInfo": {
  13. "info": "World"
  14. }
  15. }
  16. }

我已经成功创建了一个实体,可以使用外部键来表示复杂对象:

  1. "properties": {
  2. "property1": {
  3. "type": "boolean",
  4. "value": true,
  5. "valueInfo": {
  6. "info": "Hello"
  7. }
  8. },
  9. "property2": {
  10. "type": "string",
  11. "value": "string234",
  12. "valueInfo": {
  13. "info": "World"
  14. }
  15. }
  16. }

Lombok Java代码:

  1. public class ComplexObject {
  2. @JsonProperty("properties")
  3. @Valid
  4. private Map<String, PropertyValueDTO> variables = null;
  5. }
  6. public static class PropertyValueDTO {
  7. @JsonProperty("type")
  8. private ProcessVariableTypeEnum type;
  9. @JsonProperty("value")
  10. private String value;
  11. @JsonProperty("valueInfo")
  12. @Valid
  13. private Map<String, Object> valueInfo = null;
  14. }

是否可以在不需要键("properties")的情况下,从基本实体类中表示PropertyValueDTO

英文:

I want to represent a complex JSON Object using Lombok:

  1. {
  2. &quot;property1&quot;: {
  3. &quot;type&quot;: &quot;boolean&quot;,
  4. &quot;value&quot;: true,
  5. &quot;valueInfo&quot;: {
  6. &quot;info&quot;: &quot;Hello&quot;
  7. }
  8. },
  9. &quot;property2&quot;: {
  10. &quot;type&quot;: &quot;string&quot;,
  11. &quot;value&quot;: &quot;string234&quot;,
  12. &quot;valueInfo&quot;: {
  13. &quot;info&quot;: &quot;World&quot;
  14. }
  15. }
  16. }

I was able to create an Entity when I can represent the complex object using an outer key:

  1. &quot;properties&quot;: {
  2. &quot;property1&quot;: {
  3. &quot;type&quot;: &quot;boolean&quot;,
  4. &quot;value&quot;: true,
  5. &quot;valueInfo&quot;: {
  6. &quot;info&quot;: &quot;Hello&quot;
  7. }
  8. },
  9. &quot;property2&quot;: {
  10. &quot;type&quot;: &quot;string&quot;,
  11. &quot;value&quot;: &quot;string234&quot;,
  12. &quot;valueInfo&quot;: {
  13. &quot;info&quot;: &quot;World&quot;
  14. }
  15. }
  16. }

Lombok Java Code:

  1. public class ComplexObject {
  2. @JsonProperty(&quot;properties&quot;)
  3. @Valid
  4. private Map&lt;String, PropertyValueDTO&gt; variables = null;
  5. }
  6. public static class PropertyValueDTO {
  7. @JsonProperty(&quot;type&quot;)
  8. private ProcessVariableTypeEnum type;
  9. @JsonProperty(&quot;value&quot;)
  10. private String value;
  11. @JsonProperty(&quot;valueInfo&quot;)
  12. @Valid
  13. private Map&lt;String, Object&gt; valueInfo = null;
  14. }

Is it possible to represent PropertyValueDTO from a base entity class without the need for key (properties)?

huangapple
  • 本文由 发表于 2020年7月27日 22:06:44
  • 转载请务必保留本文链接:https://java.coder-hub.com/63117077.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定