mirror of
https://github.com/stleary/JSON-java.git
synced 2026-01-05 00:00:52 -05:00
save and restore the current default locale, to avoid any side effects on other executions in the same JVM
This commit is contained in:
@@ -36,25 +36,31 @@ public class JSONObjectLocaleTest {
|
|||||||
|
|
||||||
MyLocaleBean myLocaleBean = new MyLocaleBean();
|
MyLocaleBean myLocaleBean = new MyLocaleBean();
|
||||||
|
|
||||||
/**
|
// save and restore the current default locale, to avoid any side effects on other executions in the same JVM
|
||||||
* This is just the control case which happens when the locale.ROOT
|
Locale defaultLocale = Locale.getDefault();
|
||||||
* lowercasing behavior is the same as the current locale.
|
try {
|
||||||
*/
|
/**
|
||||||
Locale.setDefault(new Locale("en"));
|
* This is just the control case which happens when the locale.ROOT
|
||||||
JSONObject jsonen = new JSONObject(myLocaleBean);
|
* lowercasing behavior is the same as the current locale.
|
||||||
assertEquals("expected size 2, found: " +jsonen.length(), 2, jsonen.length());
|
*/
|
||||||
assertEquals("expected jsonen[i] == beanI", "beanI", jsonen.getString("i"));
|
Locale.setDefault(new Locale("en"));
|
||||||
assertEquals("expected jsonen[id] == beanId", "beanId", jsonen.getString("id"));
|
JSONObject jsonen = new JSONObject(myLocaleBean);
|
||||||
|
assertEquals("expected size 2, found: " +jsonen.length(), 2, jsonen.length());
|
||||||
|
assertEquals("expected jsonen[i] == beanI", "beanI", jsonen.getString("i"));
|
||||||
|
assertEquals("expected jsonen[id] == beanId", "beanId", jsonen.getString("id"));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Without the JSON-Java change, these keys would be stored internally as
|
* Without the JSON-Java change, these keys would be stored internally as
|
||||||
* starting with the letter, 'ı' (dotless i), since the lowercasing of
|
* starting with the letter, 'ı' (dotless i), since the lowercasing of
|
||||||
* the getI and getId keys would be specific to the Turkish locale.
|
* the getI and getId keys would be specific to the Turkish locale.
|
||||||
*/
|
*/
|
||||||
Locale.setDefault(new Locale("tr"));
|
Locale.setDefault(new Locale("tr"));
|
||||||
JSONObject jsontr = new JSONObject(myLocaleBean);
|
JSONObject jsontr = new JSONObject(myLocaleBean);
|
||||||
assertEquals("expected size 2, found: " +jsontr.length(), 2, jsontr.length());
|
assertEquals("expected size 2, found: " +jsontr.length(), 2, jsontr.length());
|
||||||
assertEquals("expected jsontr[i] == beanI", "beanI", jsontr.getString("i"));
|
assertEquals("expected jsontr[i] == beanI", "beanI", jsontr.getString("i"));
|
||||||
assertEquals("expected jsontr[id] == beanId", "beanId", jsontr.getString("id"));
|
assertEquals("expected jsontr[id] == beanId", "beanId", jsontr.getString("id"));
|
||||||
|
} finally {
|
||||||
|
Locale.setDefault(defaultLocale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user