Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gson SerializedName #76

Open
sarimmehdi opened this issue Dec 3, 2021 · 0 comments
Open

Add support for gson SerializedName #76

sarimmehdi opened this issue Dec 3, 2021 · 0 comments

Comments

@sarimmehdi
Copy link

Can you add support for SerializedName? This way we can assign field names different than the variable name. Example:

public class Pose {
    Camera camera;
    Anchor anchor;
    @SerializedName(value = "recording-id")
    int recordingId;
    Bbox bbox;
    @SerializedName(value = "track-id")
    int trackId;

    public Pose(Camera camera, Anchor anchor, int recordingId, Bbox bbox, int trackId) {
        this.camera = camera;
        this.anchor = anchor;
        this.recordingId = recordingId;
        this.bbox = bbox;
        this.trackId = trackId;
    }

    public void setBbox(Bbox bbox) {
        this.bbox = bbox;
    }
}

pose = new com.memex.gson.Pose(cameraJson, anchorJson, recordingId, bbox, trackId);
new TomlWriter().write(pose, poseFile);

This is incorrectly serialized as:

recordingId = -1
trackId = 0

[anchor]
latitude = 44.4259019
longitude = 8.8628793
name = "42850a73-9fbd-4ba5-a0e3-2e04644f24c1"

[anchor.orientation]
w = 0.9143955
x = 0.0
y = 0.40482244
z = 0.0

[anchor.translation]
x = -0.8728261
y = -0.30460373
z = -0.37339234

[bbox]
x1 = 360
x2 = 454
y1 = 293
y2 = 183

[camera.orientation]
w = -0.63340276
x = 0.06788388
y = 0.31760123
z = 0.702369

[camera.translation]
x = 0.11091955
y = -0.0041119093
z = -0.06686936

recordingId should be recording-id and trackId should be track-id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant