A good Java programmer tool: json-to-javabean,
I will introduce a developed tool, json-to-java. It can help java programmers to generate corresponding javabean through json. This tool is particularly useful when you need to call APIs in json return format.
Features
The java system we developed often needs to call APIs of other systems. The return formats of these APIs are usually in json format. This tool helps you convert json data into corresponding javabean. To simplify the manual copying and pasting of json attributes.
Who will benefit
If you need to call a third-party API, you may encounter the following situations:
1. the API does not provide the java sdk. to map the SDK to the java response format, you must write the SDK by yourself.
2. the API provides the SDK, but the SDK is a little heavy and does not need to be tossed
Instructions for use
Use this project now. Please visit
Http://jsontojava.sinaapp.com/
Download the code in gitnet or open index.html. Shows the page. An example is displayed by default.
1. You can paste json data in the input box on the left.
2. The corresponding javabean is displayed in the box on the right.
3. You can copy the content on the right to your project.
Supported features
Automatically identifies attribute values. Currently, int, double, string, date, boolean, array, and so on can be recognized.
For example:
1. json format"created_at": "2012-05-23T08:00:58Z"
Will be recognized as the Date type and generate attributesprivate Date createdAt
2. Recognition Array
{"Tags": [{"count": 2416, "name": "" },{ "count": 1914, "name": "fairy tale "}, {"count": 1185, "name": "St. eksauperry" },{ "count": 863, "name": "France" },{ "count ": 647, "name": "classic" },{ "count": 597, "name": "Foreign Literature" },{ "count": 495, "name ": "touched" },{ "count": 368, "name": "fable"}]}
Will be converted
public class Example { private List<Tags> tags; public void setTags(List<Tags> tags) { this.tags = tags; } public List<Tags> getTags() { return tags; }}
Automatically converts the lower-case name attribute to the hump name.
The attribute name of create_at will be converted to createdAt with the Annotation
@JsonProperty("created_at")private Date createdAt;
If json is an array, the first value in the array is automatically recognized.
In the following example, the json is determined as an array, and then the javabean is parsed using the first value of the array.
[ { "id": 1, "username": "john_smith", "email": "john@example.com" }, { "id": 2, "username": "jack_smith", "email": "jack@example.com", "name": "Jack Smith" }]
One-click Copy to clipboard
When an error occurs in json parsing, an error line is displayed.
Automatically identifies custom classes with attribute values
The value, such as the images attribute, is a custom data structure instead of a basic type (such as string and int ).
{ "id":"1003078", "images":{ "small":"http:\/\/img1.douban.com\/spic\/s1001902.jpg", "large":"http:\/\/img1.douban.com\/lpic\/s1001902.jpg", "medium":"http:\/\/img1.douban.com\/mpic\/s1001902.jpg" }}
For this type of custom class, the following processing is done:
1. The type name (class name) of the attribute is obtained by converting the attribute name. For example, if the attribute type is Imagas, the attribute name images is converted into an uppercase letter.
public class Example { private String id; private Images images;}
2. an of the custom class is generated together.
Other Instructions
- Code has been put on github, github address https://github.com/giantray/text-to-javabean
- The one-click upload function can be used only when the project is deployed on the server.