package org.minijax.json;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import jakarta.json.bind.Jsonb;
import jakarta.json.bind.JsonbBuilder;
import jakarta.json.bind.JsonbConfig;
import jakarta.json.bind.config.PropertyOrderStrategy;
import jakarta.json.bind.config.PropertyVisibilityStrategy;

public class Json {
    private static Jsonb instance;

    Json() {
        throw new UnsupportedOperationException();
    }

    public static Jsonb getObjectMapper() {
        if (instance == null) {
            final PropertyVisibilityStrategy visibility = new PropertyVisibilityStrategy() {
                @Override
                public boolean isVisible(final Field field) {
                    return true;
                }

                @Override
                public boolean isVisible(final Method method) {
                    return false;
                }
            };

            final JsonbConfig config = new JsonbConfig()
                    .withPropertyVisibilityStrategy(visibility)
                    .withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL);

            instance = JsonbBuilder.create(config);
        }
        return instance;
    }
}

@@ -315,215 +315,727 @@
 y;%0A%0A
-public class Json %7B%0A    private static Jsonb instance;%0A%0A    Json() %7B%0A        throw new UnsupportedOperationException();%0A    %7D%0A%0A    public static Jsonb getObjectMapper() %7B%0A        if (instance == null) %7B%0A    
+/**%0A * The Json class provides helper utilities for creating the singleton object mapper.%0A *%0A * For most use cases, you can simply call getObjectMapper() without anything extra.%0A *%0A * You can instantiate the singleton object mapper with a custom configuration using createObjectMapper().%0A */%0Apublic class Json %7B%0A    private static Jsonb instance;%0A%0A    Json() %7B%0A        throw new UnsupportedOperationException();%0A    %7D%0A%0A    /**%0A     * Returns the default JsonbConfig configuration.%0A     *%0A     * In addition to the standard Jsonb defaults:%0A     *     1) Uses field visibility%0A     *     2) Sorts lexicographically%0A     *%0A     * @return The default JsonbConfig.%0A     */%0A    public static JsonbConfig getDefaultConfig() %7B%0A
     
@@ -1123,36 +1123,32 @@
 ) %7B%0A            
-    
 @Override%0A      
@@ -1145,36 +1145,32 @@
 ide%0A            
- 
-   
 public boolean i
@@ -1211,28 +1211,24 @@
             
-    
 return true;
@@ -1228,20 +1228,16 @@
 n true;%0A
-    
         
@@ -1247,36 +1247,32 @@
  %7D%0A%0A            
-    
 @Override%0A      
@@ -1257,36 +1257,32 @@
       @Override%0A
-    
             publ
@@ -1337,28 +1337,24 @@
             
-   
- 
 return false
@@ -1363,34 +1363,26 @@
             
-    %7D%0A    
+%7D%0A
         %7D;%0A%0A
@@ -1393,38 +1393,14 @@
     
-  
-  final JsonbConfig config =
+return
  new
@@ -1422,36 +1422,32 @@
                 
- 
-   
 .withPropertyVis
@@ -1474,20 +1474,16 @@
 bility)%0A
-    
         
@@ -1561,58 +1561,822 @@
 L);%0A
-%0A            instance = JsonbBuilder.create(config
+    %7D%0A%0A    /**%0A     * Initializes the object mapper.%0A     *%0A     * Can only be called once.  Cannot be called after getObjectMapper().%0A     *%0A     * If you need a custom configuration, you should call this method once at the%0A     * beginning of your application.%0A     *%0A     * @param config The object mapper configuration.%0A     */%0A    public static void initObjectMapper(final JsonbConfig config) %7B%0A        if (instance != null) %7B%0A            throw new IllegalStateException(%22JSON object mapper already created%22);%0A        %7D%0A        instance = JsonbBuilder.create(config);%0A    %7D%0A%0A    /**%0A     * Returns the object mapper singleton.%0A     *%0A     * @return The object mapper singleton.%0A     */%0A    public static Jsonb getObjectMapper() %7B%0A        if (instance == null) %7B%0A            initObjectMapper(getDefaultConfig()
 );%0A 

Enable custom Jsonb config