@@ -401,12 +401,17 @@ private JSONObject(Map<?, ?> m, int recursionDepth, JSONParserConfiguration json
401401 */
402402 public JSONObject (Object bean ) {
403403 this ();
404- this .populateMap (bean );
404+ this .populateMap (bean , new JSONParserConfiguration ());
405+ }
406+
407+ public JSONObject (Object bean , JSONParserConfiguration jsonParserConfiguration ) {
408+ this ();
409+ this .populateMap (bean , jsonParserConfiguration );
405410 }
406411
407412 private JSONObject (Object bean , Set <Object > objectsRecord ) {
408413 this ();
409- this .populateMap (bean , objectsRecord );
414+ this .populateMap (bean , objectsRecord , new JSONParserConfiguration () );
410415 }
411416
412417 /**
@@ -1764,11 +1769,11 @@ public String optString(String key, String defaultValue) {
17641769 * @throws JSONException
17651770 * If a getter returned a non-finite number.
17661771 */
1767- private void populateMap (Object bean ) {
1768- populateMap (bean , Collections .newSetFromMap (new IdentityHashMap <Object , Boolean >()));
1772+ private void populateMap (Object bean , JSONParserConfiguration jsonParserConfiguration ) {
1773+ populateMap (bean , Collections .newSetFromMap (new IdentityHashMap <Object , Boolean >()), jsonParserConfiguration );
17691774 }
17701775
1771- private void populateMap (Object bean , Set <Object > objectsRecord ) {
1776+ private void populateMap (Object bean , Set <Object > objectsRecord , JSONParserConfiguration jsonParserConfiguration ) {
17721777 Class <?> klass = bean .getClass ();
17731778
17741779 // If klass is a System class then set includeSuperClass to false.
@@ -1788,7 +1793,7 @@ && isValidMethodName(method.getName())) {
17881793 if (key != null && !key .isEmpty ()) {
17891794 try {
17901795 final Object result = method .invoke (bean );
1791- if (result != null ) {
1796+ if (result != null || jsonParserConfiguration . isUseNativeNulls () ) {
17921797 // check cyclic dependency and throw error if needed
17931798 // the wrap and populateMap combination method is
17941799 // itself DFS recursive
0 commit comments