Class JsonMenuItemSerializer

java.lang.Object
com.thecoderscorner.menu.persist.JsonMenuItemSerializer

public class JsonMenuItemSerializer extends Object
Creates a menu serializer instance that can convert menu structures to and from JSON format. In the simplest case just create a new instance of the class and you can use it to convert between formats.
     var jsonSerializer = new JsonMenuItemSerializer();
     var tree = jsonSerializer.newMenuTreeWithItems(textCopiedFromTcMenuDesigner);
     var json = jsonSerializer.itemsToCopyText(MenuTree.ROOT, tree);
 
  • Constructor Details

    • JsonMenuItemSerializer

      public JsonMenuItemSerializer()
    • JsonMenuItemSerializer

      public JsonMenuItemSerializer(Consumer<com.google.gson.GsonBuilder> builder)
  • Method Details

    • getGson

      public com.google.gson.Gson getGson()
    • populateListInOrder

      public List<PersistedMenu> populateListInOrder(SubMenuItem node, MenuTree menuTree)
    • itemsToCopyText

      public String itemsToCopyText(MenuItem startingPoint, MenuTree tree)
    • copyTextToItems

      public List<PersistedMenu> copyTextToItems(String items)
    • newMenuTreeWithItems

      public MenuTree newMenuTreeWithItems(String tcMenuCopy)
    • checkItemValueCanPersist

      public static boolean checkItemValueCanPersist(PersistedMenu persistedMenu)
      There are some menu types that should not have a default value, these generally don't have a value associated with them that can be easily saved, such as lists, action items, builder items and submenus.
      Parameters:
      persistedMenu - the item to check
      Returns:
      true if the item value can be persisted, otherwise false
    • getJsonObjOrThrow

      public static com.google.gson.JsonObject getJsonObjOrThrow(com.google.gson.JsonObject object, String child) throws IOException
      Throws:
      IOException
    • getJsonStrOrThrow

      public static String getJsonStrOrThrow(com.google.gson.JsonObject object, String child) throws IOException
      Throws:
      IOException
    • getJsonIntOrThrow

      public static int getJsonIntOrThrow(com.google.gson.JsonObject object, String child) throws IOException
      Throws:
      IOException