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)
| 605 | * @throws JsonException if allowed depth has been reached |
| 606 | */ |
| 607 | private void mapObject(Object toConvert, int maxDepth, int depthRemaining) { |
| 608 | if (toConvert instanceof Class) { |
| 609 | write(((Class<?>) toConvert).getName()); |
| 610 | return; |
| 611 | } |
| 612 | |
| 613 | // Raw object via reflection? Nope, not needed |
| 614 | beginObject(); |
| 615 | for (SimplePropertyDescriptor pd : |
| 616 | SimplePropertyDescriptor.getPropertyDescriptors(toConvert.getClass())) { |
| 617 | |
| 618 | // Only include methods not on java.lang.Object to stop things being super-noisy |
| 619 | Function<Object, @Nullable Object> readMethod = pd.getReadMethod(); |
| 620 | if (readMethod == null) { |
| 621 | continue; |
| 622 | } |
| 623 | |
| 624 | if (!writeClassName && "class".equals(pd.getName())) { |
| 625 | continue; |
| 626 | } |
| 627 | |
| 628 | Object value = readMethod.apply(toConvert); |
| 629 | if (!Optional.empty().equals(value)) { |
| 630 | name(pd.getName()); |
| 631 | write0(value, maxDepth, depthRemaining - 1); |
| 632 | } |
| 633 | } |
| 634 | endObject(); |
| 635 | } |
| 636 | |
| 637 | /** Defines to common behavior of JSON containers (objects and arrays). */ |
| 638 | private abstract class Node { |
no test coverage detected