easy java solution using bst property similiar to validating bst problem
\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x)
```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\npublic class Codec {\n\n    int serializedTreeIndexPointer;\n    public String serialize(TreeNode root) {\n      StringBuilder serializedTree = new StringBuilder();\n      preorder(root, serializedTree);\n      return serializedTree.toString();\n    }\n    \n   void preorder(TreeNode root, StringBuilder serializedTree) {\n       if (root == null) {\n          return;\n       }\n\n        serializedTree.append(root.val).append(",");\n        preorder(root.left, serializedTree);\n        preorder(root.right, serializedTree);\n   }\n\n\n    // Decodes your encoded data to tree.\n    public TreeNode deserialize(String serializedTree) {\n        serializedTreeIndexPointer = 0;\n        String serializedArray[] = serializedTree.split(",");\n        return treeBuilder(serializedArray, Integer.MIN_VALUE, Integer.MAX_VALUE);\n\n    }\n    \n    TreeNode treeBuilder(String serializedArray[], int min, int max) {\n        if (serializedTreeIndexPointer >= serializedArray.length)\n            return null;\n        \n        Integer a = parseStringToInt(serializedArray[serializedTreeIndexPointer]);\n         if ( a == null || a > max || a < min) {\n          return null;\n         }\n\n       TreeNode root = new TreeNode(Integer.parseInt(serializedArray[serializedTreeIndexPointer++]));\n       root.left = treeBuilder(serializedArray, min, root.val);\n       root.right = treeBuilder(serializedArray, root.val, max);\n        \n       return root;\n    }\n    \n    Integer parseStringToInt(String s) {\n        try {\n          return Integer.parseInt(s);\n        }\n        catch (NumberFormatException e) {\n            return null;}\n    }\n}\n```
['Binary Search Tree', 'Java']