|
1 |
| -# json-java-objectifier |
2 |
| -Java tools for converting JSON into typed object structures |
| 1 | +# JSON Java Objectifier |
| 2 | + |
| 3 | +A Java library for parsing, validating, and manipulating JSON data with strong type safety and customizable object structures. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **JSON Validation**: Strict validation according to JSON specification |
| 8 | +- **Type Safety**: Strong type checking and conversion |
| 9 | +- **Custom Object Mapping**: Convert JSON to typed Java objects |
| 10 | +- **Duplicate Key Detection**: Validation for unique keys within objects |
| 11 | +- **Pretty Printing**: Configurable JSON string formatting |
| 12 | +- **Unicode Support**: Full support for Unicode characters and escape sequences |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +Add this dependency to your `pom.xml`: |
| 17 | + |
| 18 | +```xml |
| 19 | +<dependency> |
| 20 | + <groupId>com.example</groupId> |
| 21 | + <artifactId>json-java-objectifier</artifactId> |
| 22 | + <version>1.0.0</version> |
| 23 | +</dependency> |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### JSON Processing |
| 29 | + |
| 30 | +From Java String: |
| 31 | +```java |
| 32 | +String jsonString = "{\"key\":\"value\"}"; |
| 33 | +JSONObject obj = JSONProcessor.processJson("root", jsonString); |
| 34 | +``` |
| 35 | + |
| 36 | +From JSON File: |
| 37 | +```java |
| 38 | +Path jsonPath = Path.of("path", "to", "file.json"); |
| 39 | +JSONObject obj = JSONProcessor.processJson(jsonPath); |
| 40 | +``` |
| 41 | + |
| 42 | +### Validate JSON |
| 43 | + |
| 44 | +From Java String: |
| 45 | +```java |
| 46 | +String jsonString = "{\"numbers\":[1,2,3]}"; |
| 47 | +boolean isValid = JSONValidator.validateJson(jsonString); |
| 48 | +``` |
| 49 | + |
| 50 | +From JSON File: |
| 51 | +```java |
| 52 | +Path jsonPath = Path.of("path", "to", "file.json"); |
| 53 | +JSONObject obj = JSONValidator.validateJson(jsonPath); |
| 54 | +``` |
| 55 | + |
| 56 | +### Access Typed Values |
| 57 | + |
| 58 | +```java |
| 59 | +JSONObject obj = new JSONObject("key", "value"); |
| 60 | +String str = obj.getAsString(); // Type-safe string access |
| 61 | +Number num = obj.getAsNumber(); // Type-safe number access |
| 62 | +Boolean bool = obj.getAsBoolean(); // Type-safe boolean access |
| 63 | +List<?> list = obj.getAsList(); // Type-safe list access |
| 64 | +``` |
| 65 | + |
| 66 | +### Pretty Print JSON |
| 67 | + |
| 68 | +With JSONObject.toString(): |
| 69 | +```java |
| 70 | +JSONObject obj = JSONProcessor.processJson("root", jsonString); |
| 71 | +String formatted = obj.toString(); // Returns formatted JSON string |
| 72 | +``` |
| 73 | + |
| 74 | +With JSONStringifier: |
| 75 | +```java |
| 76 | +JSONObject obj = JSONProcessor.processJson("root", jsonString); |
| 77 | +String formatted = JSONStringifier.stringifyJson(obj); // Returns formatted JSON string on one line |
| 78 | +``` |
| 79 | + |
| 80 | +## Features in Detail |
| 81 | + |
| 82 | +### Type Support |
| 83 | +- Strings (with Unicode) |
| 84 | +- Numbers (Integer, Long, Double) |
| 85 | +- Objects (nested) |
| 86 | +- Arrays |
| 87 | +- Booleans |
| 88 | +- Null values |
| 89 | + |
| 90 | +### Validation |
| 91 | +- Strict JSON syntax checking (ECMA-404 specification) |
| 92 | +- Duplicate key detection |
| 93 | +- Type validation |
| 94 | +- Unicode escape sequence validation |
| 95 | + |
| 96 | +### Error Handling |
| 97 | +- Detailed error messages |
| 98 | +- Type conversion safety |
| 99 | +- Null safety |
| 100 | + |
| 101 | +## Building from Source |
| 102 | + |
| 103 | +```bash |
| 104 | +git clone https://github.com/stevenlagoy/json-java-objectifier.git |
| 105 | +cd json-java-objectifier |
| 106 | +mvn clean install |
| 107 | +``` |
| 108 | + |
| 109 | +## Requirements |
| 110 | + |
| 111 | +- Java 21 or higher |
| 112 | +- Maven 3.x |
| 113 | + |
| 114 | +## Contributing |
| 115 | + |
| 116 | +1. Fork the repository |
| 117 | +2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
| 118 | +3. Commit your changes (`git commit -m 'Add some amazing feature'`) |
| 119 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 120 | +5. Open a Pull Request |
| 121 | + |
| 122 | +## License |
| 123 | + |
| 124 | +This project is licensed under the MIT License - see the LICENSE file for details. |
| 125 | + |
| 126 | +## Acknowledgments |
| 127 | + |
| 128 | +- Built with Java 21 |
| 129 | +- Uses JUnit for testing |
| 130 | +- SpotBugs for code quality |
| 131 | +- Maven for build management |
0 commit comments