需要帮助来解析此JSON

问题描述

我有以下格式的JSON文件。第一个对象是客户信息,第二个对象是订单信息,后跟n个对象,用于订购的每个零件的详细信息。我需要将其转换为Java POJO。

这是JSON的样子。它来自外部供应商,所以我必须按原样使用它。

function calculateTextLines(context,maxWidth,lineHeight) {
    minimum_text_width = 0
    let words = text.split(' ')
    let line = ''
    let lines = []

    // # Generates an array of wrapped line and
    // # calculates the height of future text to center it later
    for (let n = 0; n < words.length; n++) {
        // # The next 3 lines calculates minimum possible width of the text Box
        let minimum_text_width_metrics = context.measureText(words[n])
        if (minimum_text_width_metrics.width > minimum_text_width)
            minimum_text_width = minimum_text_width_metrics.width

        let testLine = line + words[n] + ' '
        let metrics = context.measureText(testLine)
        let testWidth = metrics.width
        if (testWidth > maxWidth && n > 0) {
            lines.push(line)
            line = words[n] + ' '
        } else {
            line = testLine
        }
    }
    lines.push(line)

    if (minimum_text_width > canvas.width)
        minimum_text_width = canvas.width

    return lines
}


function calculateNewHeight(new_width,fontsize) {
    let ctx = canvas.getContext('2d')
    ctx.save()

    ctx.font = fontsize + 'px ' + font.family
    ctx.textAlign = font.align
    const lines = calculateTextLines(ctx,new_width,font.line - height * fontsize)

    ctx.restore()
    return lines.length * (font.line - height * fontsize)
}

我创建了四个类:{ "report_title": "title","result_date": "08/12/2020 22:40:51","company": "company name","add1": "123 main st","add2": null,"city": "some city","state": "state","country": "United States of America","zip": "12345","name": "first last","username": "firstlast","role": "Manager" },{ "launch_date": "08/12/2020 19:05:19","client": "client1","order_number": "1","total_orders": "1","type": "type","status": "Finished","reference": "order reference","fulfill": "some name","duration": "00:07:12","order title": "title","order_groups": null,"part_nums": "1,2,3",},{ "part_num": "1234","name": "asdf","other_name": "asdf","manufacturer": "aasdf","status": "asdfasf","id": 12345,"title": "some title","type": "Ig","notes": "long winded notes","impact": null,"solution": null,{ "part_num": "1235","name": "asdf1","other_name": "asdf1","manufacturer": "aasdf1","status": "asdfasf1","id": 12346,} ... CustomerOrderInfo,并包含了OrderDetail类。

Order

我正在尝试使用class Order { Customer customer OrderInfo orderInfo; List<OrderDetail> orderDetailList; } ,但是我只得到了客户对象,而没有其他东西。任何帮助表示赞赏。

编辑: 这是我尝试过的

ObjectMapper

解决方法

我想我提这个问题太早了。

我接受了Ajay Kr Choudhary的建议,并分别解析了每个节点并分别映射了它们。虽然没有我想要的高效或自动化,但总比没有好。

 JsonNode rootNode = mapper.readTree(inputFile);
 Customer customer = mapper.treeToValue(rootNode.get(0),Customer.class);
 OrderInfo orderInfo = mapper.treeToValue(rootNode.get(1),OrderInfo.class);
 OrderDetail orderDetail = mapper.treeToValue(rootNode.get(2),OrderDetail.class);