I was fed up with writing Java classes to mirror json models. So I wrote this Java app to automate the process.

Overview

Json2Java

I was fed up with writing Java classes to mirror json models. So I wrote this Java app to automate the process.

What this tool can do right now:

Give it:
  • a url to a json file
  • a package name for the classes it will generate
  • the name of the base class to start with.
  • optionally, the p option will make your classes parcelable.
  • optionally, the g option will give your classes gson annotations for serialization.
  • optionally, the s option will override the toString method.

It will create the folder structure for the package you provide, then it will read the json at the url you provide, and output java classes into a zip file.

The easiest way to actuall use this is to go to http://jsontojava.appspot.com/
There you can just put in the variables and click download.

When run from the commandline, it looks like this:

java -jar JsonToJava.jar -url http://example.com/folder.json -package com.example.api.model -class Folder -p -g

Each class will implement Parcelable for easy passing of information in Android (optional). Each class will have a default empty constructor. The members of each class will follow Android naming conventions with an "m" prefix and camel case. Each member will have a corresponding static final String that relates it to it's json counterpart Each member will have a @SerializedName annotation for very easy Gson parsing. (optional) If a member called "mId" or "mUniqueId" is found, then equals and hashcode will be overridden so comparisons are made on the id.

What I want this tool to do in the future in no particular order

  • Accept either a url or a block of json pasted in a text box
  • Extract superclasses
  • Accept multiple urls to build up the whole model
  • Allow the user to choose between Gson annotations, Jackson annotations, org.json constructors and toJson() methods, or none of the above
  • Give users the ability to rename classes
  • Give users the ability to ignore classes
You might also like...
Android library that manages your app's cached data with ease.
Android library that manages your app's cached data with ease.

Teller Android library that makes your apps faster. Teller facilitates the downloading, saving, and reading of the cached data of your app. Keep your

基于Appium的 App UI 遍历 & Monkey工具 (支持操作步骤回放)
基于Appium的 App UI 遍历 & Monkey工具 (支持操作步骤回放)

UICrawler 基于Appium的App UI遍历 & Monkey 工具 针对个人和公司提供有偿UI自动化技术、接口自动化技术、接口mock技术等培训及测试工具定制开发 QQ 技术交流群 : 728183683 环境搭建及基本使用说明 环境搭建(感谢网友harsayer倾力之作): https

Demonstration of calling requestFocusFromTouch() in WebView is changing colors in Android app
Demonstration of calling requestFocusFromTouch() in WebView is changing colors in Android app

webview-changing-colors-bug Demonstration of calling requestFocusFromTouch() in WebView is changing colors in Android app This is the problematic code

Makes Google play in app purchase library (BillingClient) into a flowable that can easily be used in compose world

Billy the android Our goal is to make a modern api of BillingClient so that it is easier to use in compose world. This library is still early beta and

The Android Version in Kotlin of The Dialer App (in SwiftUI)

Dialer An intuitive USSD client to handle most of the common actions for you. Contains common MTN Rwanda USSD activation codes, which drastically simp

Extension for Voisek App on React Native

react-native-voisek-app-extension Voisek App Extension for React Native Installation npm install react-native-voisek-app-extension Usage import Voisek

Android App development internship project to create woman home screen for clothing company The Swastika.

Android App development internship project to create woman home screen for clothing company The Swastika.

Brief description of the app architecture
Brief description of the app architecture

Readme App Brief description of the app architecture The application has a simple MVVM architecture based on a single Activity coupled with his own Vi

Recruitment Task App - record time which a user spends on tasks defined by himself

Recruitment-Task The purpose of this application is to record time which a user spends on tasks defined by himself. The user can add new tasks. New ta

Comments
  • Implement toString()

    Implement toString()

    It would be helpful if you could also generate the toString() method for each model class. It should output the values for each member variable. Here is an example:

    @Override
    public String toString() {
        return "deg = " + mDeg + ", gust = " + mGust + ", speed = " + mSpeed;
    }
    

    In the UI you can add an option to let the user decide whether the method should be generated.

    opened by johnjohndoe 3
  • Uses this data, finally generates the result is not right.

    Uses this data, finally generates the result is not right.

    {"liveInfo":[{"id":"info","des":"","audio":"http://live.3gv.hehe.com/101","bkgURL":"http://y0.heheimg.com/a/2014_10/e08b6b07cb74d3f.jpg","channelId":"4AC51C17-9FBE-47F2-8EE0-8285A66EAFF5","unVideo":"http://live.cuff.hehe.com/zixun.m3u8","name":"hehe","smallIconURL":"http://y1.heheimg.com/a/2014_10/ccddb083e872c7b.png","unAudio":"http://live.cuff.hehe.com/101","bigIconURL":"http://y3.heheimg.com/a/2014_10/3ceafc4fb3b0b00.png","video":"http://live.3gv.hehe.com/zixun.m3u8"},{"id":"chinese","des":"","audio":"http://live.3gv.hehe.com/102","bkgURL":"http://y2.heheimg.com/a/2014_10/4a5c63674d61418.jpg","channelId":"270DE943-3CDF-45E1-8445-9403F93E80C4","unVideo":"http://live.cuff.hehe.com/zhongwen.m3u8","name":"hehehuhu","smallIconURL":"http://y1.heheimg.com/a/2014_10/1ee94d0bfb238a9.png","unAudio":"http://live.cuff.hehe.com/102","bigIconURL":"http://y1.heheimg.com/a/2014_10/38cf06f306393ef.png","video":"http://live.3gv.hehe.com/zhongwen.m3u8"},{"id":"hongkong","des":"","audio":"http://live.3gv.hehe.com/103","bkgURL":"http://y3.heheimg.com/a/2014_10/1e65a127e23bc1a.jpg","channelId":"2c942450-2165-4750-80de-7dff9c224153","unVideo":"http://live.cuff.hehe.com/hongkong.m3u8","name":"hehexxxx","smallIconURL":"http://y3.heheimg.com/a/2014_10/477fb893c64278d.png","unAudio":"http://live.cuff.hehe.com/103","bigIconURL":"http://y3.heheimg.com/a/2014_10/0b7ae487eb72af1.png","video":"http://live.3gv.hehe.com/hongkong.m3u8"},{"id":"cctv13","des":"","audio":"http://live.3gv.hehe.com/161","bkgURL":"http://y0.heheimg.com/a/2014_10/58296d58098f3a4.jpg","channelId":"5435BFA3-210B-4F4F-A90F-BCB1C4C40D59","unVideo":"http://live.cuff.hehe.com/cctv13.m3u8","name":"CCTV13","smallIconURL":"http://y3.heheimg.com/a/2014_10/0cd0c207cf2dc10.png","unAudio":"http://live.cuff.hehe.com/161","bigIconURL":"http://y3.heheimg.com/a/2014_10/bec87305e93dba6.png","video":"http://live.3gv.hehe.com/cctv13.m3u8"},{"id":"ahws","des":"","audio":"http://live.3gv.hehe.com/165","bkgURL":"http://y0.heheimg.com/a/2014_10/7b8ff78bfc711d0.jpg","channelId":"8550DAD6-8724-4474-8A95-F30967CAA294","unVideo":"http://live.cuff.hehe.com/ZJWS.m3u8","name":"fdsfsfd","smallIconURL":"http://y1.heheimg.com/a/2014_10/177e597345de785.png","unAudio":"http://live.cuff.hehe.com/165","bigIconURL":"http://y0.heheimg.com/a/2014_10/a2bf9373fdb4a43.png","video":"http://live.3gv.hehe.com/ZJWS.m3u8"},{"id":"tjws","des":"","audio":"http://live.3gv.hehe.com/166","bkgURL":"http://y2.heheimg.com/a/2014_10/8b8965f5c5ebcfc.jpg","channelId":"35383695-26c3-4ce5-b535-0001abce11e4","unVideo":"http://live.cuff.hehe.com/CQWS.m3u8","name":"sdfsdfs","smallIconURL":"http://y3.heheimg.com/a/2014_10/54d1e174ec8d781.png","unAudio":"http://live.cuff.hehe.com/166","bigIconURL":"http://y1.heheimg.com/a/2014_10/f55c789dc554969.png","video":"http://live.3gv.hehe.com/CQWS.m3u8"},{"id":"szws","des":"","audio":"http://live.3gv.hehe.com/167","bkgURL":"http://y3.heheimg.com/a/2014_10/3c1a861ac668f1a.jpg","channelId":"3072FC61-4763-4BE9-AA19-2B241498775A","unVideo":"http://live.cuff.hehe.com/SZWS.m3u8","name":"sdfsfsf","smallIconURL":"http://y0.heheimg.com/a/2014_10/f2aa7a7b8cabf36.png","unAudio":"http://live.cuff.hehe.com/167","bigIconURL":"http://y0.heheimg.com/a/2014_10/eb2b80875e98698.png","video":"http://live.3gv.hehe.com/SZWS.m3u8"}]}

    opened by crazier9527 2
  • NPE

    NPE

    Created PublicIpAddress.java
    Created InnerIpAddress.java
    Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
    Caused by: java.lang.NullPointerException
        at com.jsontojava.Member.getGetterSignature(Member.java:104)
        at com.jsontojava.Member.getGetter(Member.java:125)
        at com.jsontojava.NewType.toString(NewType.java:128)
        at com.jsontojava.Main.main(Main.java:90)
    
    opened by teaey 1
  • code generation renames the reference variables, class names randomly

    code generation renames the reference variables, class names randomly

    1> { "responseCode": "200", "responseMessage": "OK" }

    private String mResponseMessage this should be responseCode. when we use GSON parsing it's really helpful.

    2> I also observed if the Json object prefix is { "Options" :{.....}} the class name changes from Options to Option.java !! it should be Options.java

    3> "doc_value": "a2" after code generation changes to String mDocValue; this is not good! we have to rename it again or we have to use @SerializedName("3") annotations!

    opened by LOG-TAG 0
Owner
Jon F Hancock
I've been an Android developer since 2010. I care deeply about inclusion. I've worked as an independent dev, at an agency, and now I do product dev work.
Jon F Hancock
Multitask、MultiThread(MultiConnection)、Breakpoint-resume、High-concurrency、Simple to use、Single/NotSingle-process

FileDownloader Android multi-task file download engine. 中文文档 FileDownloader2 Now, FileDownloader2-OkDownload is released, okdownload will contain all

LAIX Inc. (formerly LingoChamp Inc.) 10.7k Jan 3, 2023
A gradle plugin for getting java lambda support in java 6, 7 and android

Gradle Retrolambda Plugin This plugin will automatically build your java or android project with retrolambda, giving you lambda goodness on java 6 or

Evan Tatarka 5.3k Jan 5, 2023
ZXing ("Zebra Crossing") barcode scanning library for Java, Android

Project in Maintenance Mode Only The project is in maintenance mode, meaning, changes are driven by contributed patches. Only bug fixes and minor enha

ZXing Project 30.5k Dec 27, 2022
Google core libraries for Java

Guava: Google Core Libraries for Java Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multi

Google 46.5k Jan 1, 2023
AndroidPermissions 4.2 0.0 Java Android M was added to check Permission. but Permission check processing is so dirty.

Android Permissions Checker Android M was added to check Permission. but Permission check processing is so dirty. This Project is to be simple, Checki

Steve SeongUg Jung 340 Nov 11, 2022
A Java client for the Sixpack A/B testing framework https://github.com/seatgeek/sixpack

sixpack-java A Java client for SeatGeek's Sixpack a/b testing framework: https://github.com/seatgeek/sixpack Installing Sixpack-java is currently only

null 135 Oct 7, 2022
Simple Artificial Neural Network java library

SANN Simple Artificial Neural Network java library WIP Creating neural network Variant 1 //create new net (input, hidden, default len, output) Net net

Korpusov Maxim 14 Oct 11, 2022
Experimental optical character recognition app

android-ocr An experimental app for Android that performs optical character recognition (OCR) on images captured using the device camera. Runs the Tes

Robert Theis 2.2k Dec 23, 2022
A plug and play ;) android library for displaying a "rate this app" dialog

Easy Rating Dialog This lib provides a simple way to display an alert dialog for rating app. Default conditions to show: User opened the app more than

Fernando Martínez 111 Dec 30, 2022
Tool for Android app development

RateMeMaybe Asks the user if (s)he wants to open the Play Store to rate your application when certain requirements are met (see below). This can and s

Nicolai Spohrer 98 Dec 30, 2022