我绝不是一个Jackon/JSON向导,这可能从我遇到的以下问题中可以看出:
我有两种可能的数据结构.第一个叫做amountTransaction:
{
"amountTransaction": {
"clientCorrelator":"54321",
"endUserId":"tel:+16309700001"
}
}
Run Code Online (Sandbox Code Playgroud)
其中由以下Java对象表示:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonTypeName(value = "amountTransaction")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AmountTransaction {
private String clientCorrelator;
private String endUserId;
...
}
Run Code Online (Sandbox Code Playgroud)
但是,amountTransaction对象也显示为paymentTransactionNotification对象的子元素:
{
"paymentTransactionNotification": {
"amountTransaction": {
"clientCorrelator": "54321",
"endUserId": "tel:+16309700001"
}
}
}
Run Code Online (Sandbox Code Playgroud)
..我认为会代表:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
@JsonTypeName(value = "paymentTransactionNotification")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class PaymentTransactionNotification {
private AmountTransaction amountTransaction;
...
}
Run Code Online (Sandbox Code Playgroud)
仅使用amountTransaction对象解析JSON就可以了.这是一个非常简单的WRAPPER_OBJECT示例.
但是,在尝试解析paymentTransactionNotification的JSON时,我收到一个异常,表明它无法正确处理amountTransaction作为paymentTransactionNotification的元素:
com.fasterxml.jackson.databind.JsonMappingException: Could not resolve type id 'clientCorrelator' …Run Code Online (Sandbox Code Playgroud) 以下示例:我有一个struts动作的超类和子类.超类定义@Results,子类需要定义其他特定@Result条目.例如:
@Results({
@Result(name=BaseAction.ERROR, location="/WEB-INF/jsp/error.jsp")
})
public abstract class BaseAction extends ActionSupport implements ServletRequestAware {
...
}
Run Code Online (Sandbox Code Playgroud)
..和一个子类
@Results({
@Result(name=BaseAction.INDEX, location="/WEB-INF/jsp/reporting/index.jsp")
})
public class ReportAction extends BaseAction {
...
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否ReportAction的实例只有具备@Result的INDEX定义,或者它也包含任何@Result在任何定义的项目,如果它的父类.我是否ReportAction知道为BaseAction.ERROR?? 设置的位置?
谢谢,马丁
我需要生成模板文档的自定义PDF副本.最简单的办法-我想-是创建具有这样的定制需要的情况发生,即一些占位符文本源PDF <first_name>和<last_name>,然后用正确的值替换这些.
我搜索过高和低,但实际上没有办法基本上采用源模板PDF,用实际值替换占位符并写入新的PDF?
我查看了PyPDF2和ReportLab,但似乎都无法做到.有什么建议?我的大多数搜索都使用了Perl应用程序CAM :: PDF,但我更喜欢将它全部保存在Python中.
java ×2
annotations ×1
jackson ×1
json ×1
pdf ×1
python ×1
struts2 ×1
superclass ×1
wrapper ×1