Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vedenin
committed
Apr 21, 2016
1 parent
9601da7
commit e2865cb
Showing
6 changed files
with
89 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/Human.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
package ig_json_parser; | |||
|
|||
import com.instagram.common.json.annotation.JsonField; | |||
import com.instagram.common.json.annotation.JsonType; | |||
|
|||
/** | |||
* Created by vedenin on 22.04.16. | |||
*/ | |||
@JsonType | |||
public class Human { | |||
@JsonField(fieldName="message") | |||
public String message; | |||
@JsonField(fieldName="place") | |||
public Place place; | |||
|
|||
|
|||
|
|||
public void say() { | |||
System.out.println(); | |||
System.out.println(message + " , " + place.name + "!"); | |||
} | |||
} |
19 changes: 18 additions & 1 deletion
19
helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/IgJsonParserHelloWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,12 +1,29 @@ | |||
package ig_json_parser; | package ig_json_parser; | ||
|
|
||
import com.instagram.common.json.annotation.JsonField; | |||
import com.instagram.common.json.annotation.JsonType; | |||
|
|||
/** | /** | ||
* Ig Json Parser Hello World | * Ig Json Parser Hello World | ||
* | * | ||
*/ | */ | ||
public class IgJsonParserHelloWorld { | public class IgJsonParserHelloWorld { | ||
|
|
||
public static void main(String[] args) { | public static void main(String[] args) throws Exception { | ||
// init class | |||
Place place = new Place(); | |||
place.name = "World"; | |||
|
|||
Human human = new Human(); | |||
human.message = "Hi"; | |||
human.place = place; | |||
|
|||
// convert to json | |||
String jsonString = Human__JsonHelper.serializeToJson(human); | |||
System.out.println("json " + jsonString); //print "json {"place":{"name":"World"},"message":"Hi"}" | |||
|
|
||
// convert from json | |||
Human newHuman = Human__JsonHelper.parseFromJson(jsonString); | |||
newHuman.say(); // print "Hi , World!" | |||
} | } | ||
} | } |
13 changes: 13 additions & 0 deletions
13
helloworlds/3.8-json/ig_json_parser/src/main/java/ig_json_parser/Place.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
package ig_json_parser; | |||
|
|||
import com.instagram.common.json.annotation.JsonField; | |||
import com.instagram.common.json.annotation.JsonType; | |||
|
|||
/** | |||
* Created by vedenin on 22.04.16. | |||
*/ | |||
@JsonType | |||
public class Place { | |||
@JsonField(fieldName="name") | |||
public String name; | |||
} |