google / gson

A Java serialization/deserialization library to convert Java Objects into JSON and back
Apache License 2.0
23.3k stars 4.28k forks source link

Invalid de-serialization for complex input #1752

Closed dinuta closed 4 years ago

dinuta commented 4 years ago

Let's suppose we have a JSON

{
    "code": 1000,
    "message": "Success",
    "description": {
        "finished": true,
        "started": false,
        "startedat": "2020-08-14 08:47:59.193872",
        "finishedat": "2020-08-14 08:47:59.195087",
        "duration": 0.001,
        "pid": 2315,
        "id": "none",
        "commands": {
            "-cmd replaceTextInFile -arg \"/home/greg/install4j/response.varfile;{DB_PORT2};3306;false\"": {
                "status": "finished",
                "details": {
                    "out": "",
                    "err": "",
                    "code": 0,
                    "pid": 2315,
                    "args": [
                        "/home/greg/install4j/response.varfile",
                        "{DB_PORT2}",
                        "3306",
                        "false"
                    ]
                },
                "startedat": "2020-08-14 08:47:59.193888",
                "finishedat": "2020-08-14 08:47:59.194963",
                "duration": 0.001
            }
        }
    },
    "time": "2020-08-14 08:47:59.195114",
    "name": "estuary-agent",
    "version": "4.0.8"
}

And a Glue class as per this example: https://github.com/dinuta/estuary-agent-java/blob/078f14df94caa49aabea7c8a184dd03991f0e8d3/src/main/java/com/github/dinuta/estuary/agent/model/api/CommandDescription.java#L9

The result of the de-serialization context puts line: -cmd replaceTextInFile -arg \"/home/greg/install4j/response.varfile;{DB_PORT2};3306;false\" into -cmd replaceTextInFile -arg "/home/greg/install4j/response.varfile;{\n\t\t\tDB_PORT2\t\t};3306;false"

Gson version: https://mvnrepository.com/artifact/com.google.code.gson/gson/2.3.1

Later edit: I will try with the latest version

dinuta commented 4 years ago

Confirmed on 2.8.5

dinuta commented 4 years ago

For rapid tests you can take the dep:

com.github.dinuta.estuary agent 4.0.8-SNAPSHOT
dinuta commented 4 years ago

Closing issue. I used toFormattedString() for one object and not toString()