A JSON wrapper type for JSONB data obtained from the database. The wrapper represents JSONB #data() in serialised string form. A CAST(NULL AS JSONB) value is represented by a null reference of type JSONB, not as data() == null . This is consi
| 76 | * The {@link #data()} content, however, is not normalised. |
| 77 | */ |
| 78 | public final class JSONB implements Data { |
| 79 | |
| 80 | private final String data; |
| 81 | private transient Object parsed; |
| 82 | |
| 83 | private JSONB(String data) { |
| 84 | this.data = String.valueOf(data); |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | @NotNull |
| 89 | public final String data() { |
| 90 | return data; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Create a new {@link JSONB} instance from string data input. |
| 95 | */ |
| 96 | @NotNull |
| 97 | public static final JSONB valueOf(String data) { |
| 98 | return new JSONB(data); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Create a new {@link JSONB} instance from string data input. |
| 103 | * <p> |
| 104 | * This is the same as {@link #valueOf(String)}, but it can be static |
| 105 | * imported. |
| 106 | */ |
| 107 | @NotNull |
| 108 | public static final JSONB jsonb(String data) { |
| 109 | return new JSONB(data); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Create a new {@link JSONB} instance from string data input, or |
| 114 | * <code>null</code> if the input is <code>null</code>. |
| 115 | */ |
| 116 | @Nullable |
| 117 | public static final JSONB jsonbOrNull(String data) { |
| 118 | return data == null ? null : jsonb(data); |
| 119 | } |
| 120 | |
| 121 | private final Object parsed() { |
| 122 | if (parsed == null) { |
| 123 | try { |
| 124 | parsed = Internal.parseJSON(data); |
| 125 | } |
| 126 | catch (ParserException e) { |
| 127 | parsed = data; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | return parsed; |
| 132 | } |
| 133 | |
| 134 | // ------------------------------------------------------------------------- |
| 135 | // The Object API |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…