我有一个具有以下属性的模型'NewModel'
import com.fasterxml.jackson.databind.JsonNode;
@ApiModel(
description = "Data Class to hold new details"
)
public class NewModel {
@ApiModelProperty(
notes = "Value in JSON key:value format. Can be any key:value pair",
example = "{ds:2017:08:05,hh:11}"
)
private final JsonNode value;
(... getters and setters ...)
}
除此之外,我还有一些rest控制器,它们在请求主体中获取JSON。我使用此模型从请求主体获取JSOn。
我已经使用maven配置springfox swagger,并生成了api定义。但是在生成的API定义中,此模型已生成为
"NewModel": {
"type": "object",
"properties": {
"value": {
"example": "{nds:2017:08:05,hh:11}",
"description": "Value of the stamp in JSON key:value format",
"$ref": "#/definitions/JsonNode"
}
},
"description": "Data Class to hold details"
}
生成的参考JsonNode定义为
"definitions": {
"JsonNode": {
"type": "object",
"properties": {
"array": {
"type": "boolean"
},
"bigDecimal": {
"type": "boolean"
},
"bigInteger": {
"type": "boolean"
},
"binary": {
"type": "boolean"
},
"boolean": {
"type": "boolean"
},
"containerNode": {
"type": "boolean"
},
"double": {
"type": "boolean"
},
"float": {
"type": "boolean"
},
"floatingPointNumber": {
"type": "boolean"
},
"int": {
"type": "boolean"
},
"integralNumber": {
"type": "boolean"
},
"long": {
"type": "boolean"
},
"missingNode": {
"type": "boolean"
},
"nodeType": {
"type": "string",
"enum": [
"ARRAY",
"BINARY",
"BOOLEAN",
"MISSING",
"NULL",
"NUMBER",
"OBJECT",
"POJO",
"STRING"
]
},
"null": {
"type": "boolean"
},
"number": {
"type": "boolean"
},
"object": {
"type": "boolean"
},
"pojo": {
"type": "boolean"
},
"short": {
"type": "boolean"
},
"textual": {
"type": "boolean"
},
"valueNode": {
"type": "boolean"
}
}
}
现在,当我使用此API定义生成客户端库时,客户端允许的 JsonNode对象只有布尔变量 ,并且我无法分配实际的JSON字符串,因此 无法将JSON值 传递到连接服务器(我从中生成了API定义)
我想知道是否有一种方法可以使用昂首阔步的生成库将Json Strings从客户端传递到服务器。或其他可以达到所需最终结果的方向。
感谢(对冗长的帖子表示歉意)
答案 0 :(得分:1)
ApiModelProperty中的属性 dataType =“ java.util.Map” 应该有帮助
div class="container-fluid">
<div class="row">
{% for post in post_list %}
<div class="col-auto">
<div class="card border-primary mb-3">
<a href="{% url 'post_detail' post.slug %}">
<img style="height: 200px; width: 100%; display: block;" src="{{ post.thumb.url }}" alt="Card image">
</a>
<div class="card-header">
Header
</div>
<div class="card-body">
<h4 class="card-title">{{ post.title }}</h4>
<p class="card-text">{{ post.content|slice:":200" }}</p>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
答案 1 :(得分:0)
也许在Springfox中引入的AlternateTypeRuleConvention
会为您提供帮助。
例如,您可以执行以下操作:
@Bean
public AlternateTypeRuleConvention typeConvention(final TypeResolver resolver) {
return new AlternateTypeRuleConvention() {
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
@Override
public List<AlternateTypeRule> rules() {
return Collections.singletonList(
AlternateTypeRules.newRule(resolver.resolve(JsonNode.class), resolver.resolve(jsonNodeApi()))
);
}
};
}
private Type jsonNodeApi() {
return new AlternateTypeBuilder()
.fullyQualifiedClassName(
String.format("%s.generated.%s",
JsonNode.class.getPackage().getName(),
JsonNode.class.getSimpleName()))
.build();
}
AlternateTypeBuilder
还允许您在必要时指定自定义字段。