Convert the specified Java object via accessors that conform to the JavaBean specification. @param toConvert Java object to be converted @param maxDepth maximum depth of nested object traversal @param depthRemaining allowed traversal depth remaining @throws JsonException if allowed depth ha
(Object toConvert, int maxDepth, int depthRemaining)
| 532 | * @throws JsonException if allowed depth has been reached |
| 533 | */ |
| 534 | private void mapObject(Object toConvert, int maxDepth, int depthRemaining) { |
| 535 | if (toConvert instanceof Class) { |
| 536 | write(((Class<?>) toConvert).getName()); |
| 537 | return; |
| 538 | } |
| 539 | |
| 540 | // Raw object via reflection? Nope, not needed |
| 541 | beginObject(); |
| 542 | for (SimplePropertyDescriptor pd : |
| 543 | SimplePropertyDescriptor.getPropertyDescriptors(toConvert.getClass())) { |
| 544 | |
| 545 | // Only include methods not on java.lang.Object to stop things being super-noisy |
| 546 | Function<Object, @Nullable Object> readMethod = pd.getReadMethod(); |
| 547 | if (readMethod == null) { |
| 548 | continue; |
| 549 | } |
| 550 | |
| 551 | if (!writeClassName && "class".equals(pd.getName())) { |
| 552 | continue; |
| 553 | } |
| 554 | |
| 555 | Object value = readMethod.apply(toConvert); |
| 556 | if (!Optional.empty().equals(value)) { |
| 557 | name(pd.getName()); |
| 558 | write0(value, maxDepth, depthRemaining - 1); |
| 559 | } |
| 560 | } |
| 561 | endObject(); |
| 562 | } |
| 563 | |
| 564 | /** Defines to common behavior of JSON containers (objects and arrays). */ |
| 565 | private abstract class Node { |
no test coverage detected