Skip to content

Construct a JSONObject from an Object using bean getters is inconsistent across locales #315

@jakope0003

Description

@jakope0003

Construct a JSONObject from an Object using bean getters produce unexpected result when locale is set to Turkey.

Having following two classes Bean.java and JSONIssue.java.

public class Bean {

    private final String id;

    public Bean(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

}
import java.util.Locale;
import org.json.JSONObject;

public class JSONIssue {

    public static void main(String[] args) {
        Locale.setDefault(new Locale("en"));
        JSONObject jsonen = new JSONObject(new Bean("beanId"));
        System.out.println("jsonen " + jsonen);

        Locale.setDefault(new Locale("tr"));
        JSONObject jsontr = new JSONObject(new Bean("beanId"));
        System.out.println("jsontr " + jsontr);
    }

}

Output differs for different locales.

jsonen {"id":"beanId"}
jsontr {"?d":"beanId"}

I'm expecting to have consistent id key no matter what locale is set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions