我需要处理一个JSON -它有重复的组,我需要将其转换为固定长度的记录
{
"blockType" : "BL-H ",
"blockTypeLength" : "00000031",
"blockId" : "S62951156229900",
"totalNoOfTX" : "001",
"msgblockType" : "TX-S ",
"messageLength" : "00000728",
"noa":[
{
"title":"Behin",
"artist":"LIMP ",
"itunes_link":"http:behind"
},
{
"title":"Alone",
"artist":"ALYSS",
"itunes_link":"http:clk.doubler.com"
}
]
}
应转换为BehinLIMPclk.doubler.com
请求中可以有一个或多个这样的组
我试过的-
第一个
我已经使用了相应的模型来保存json和@FixedLengthRecord的值,需要帮助来理解和解决这个问题。
public class ZvkkRequest {
@DataField(pos = 1, length=5, align = "L", paddingChar=' ')
private String blockType;
@DataField(pos = 2, length=8, align = "R", paddingChar='0')
private int blockTypeLength;
@DataField(pos = 3, length=15, align = "L", paddingChar=' ')
private String blockId;
@DataField(pos = 4, length=3, align = "R", paddingChar='0')
private int totalNoOfTX;
@DataField(pos = 5, length=5, align = "L", paddingChar=' ')
private String msgblockType;
@DataField(pos = 6, length=8, align = "R", paddingChar='0')
private int messageLength;
@OneToMany(mappedTo = "classpath.DAOFix")
private List<DAOFix> repeatingGrp;
}
class DAOFix {
@DataField(pos = 7, length=5, align = "R", paddingChar=' ')
private String title;
@DataField(pos = 8, length=5, align = "R", paddingChar=' ')
private String artist;
@DataField(pos = 9, length=5, align = "R", paddingChar=' ')
private String itunes_link;
}
1条答案
按热度按时间eiee3dmh1#
经过测试,
@OneToMany
似乎不能像BindyCsvDataFormat
那样与BindyFixedLengthDataFormat
一起工作,这意味着您可能会处理json并创建多个对象示例,然后您可以使用Bindy将这些示例编组为固定长度的记录。下面是我用来测试这一点的代码,以及一种将单个
ZvkkRequest
示例转换为ZvkkRequestFixedLenght
示例列表的方法(direct:bindyFixedLenghtProcessed
),然后可以将这些示例列表编组为BindyFixedLengthDataFormat
绑定固定长度已处理测试记录以下内容:
如果您希望将这些条目放在单行上,您可以尝试分别编组
ZvkkRequest
和DAOFix
,并使用字符串连接将解组的DAOFix
条目组合到解组的ZvkkRequest
中。Zvkk请求.java
动态数据库修复程序.java
Zvkk请求固定长度.java