Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
distributed-computing-assignements
2-restAPIs-1-develop-rest-api
Commits
5bb99998
Commit
5bb99998
authored
Oct 20, 2020
by
DANIEL DIAZ SANCHEZ
Browse files
Update README.md
parent
583a7983
Changes
1
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
5bb99998
...
...
@@ -261,14 +261,21 @@ public class TestJSON {
public
TestJSON
()
{
// Crear un JSON
Collection
<
Employee
>
colection
=
new
ArrayList
<
Employee
>();
Employee
e1
=
new
Employee
(
"John"
,
"Doe"
);
Employee
e2
=
new
Employee
(
"Anna"
,
"Smith"
);
Employee
e3
=
new
Employee
(
"Peter"
,
"Jones"
);
Employee
e1
=
new
Employee
();
e1
.
firstName
=
"John"
;
e1
.
lastName
=
"Doe"
;
Employee
e2
=
new
Employee
();
e1
.
firstName
=
"Anna"
;
e1
.
lastName
=
"Smith"
;
Employee
e3
=
new
Employee
();
e1
.
firstName
=
"Peter"
;
e1
.
lastName
=
"Jones"
;
colection
.
add
(
e1
);
colection
.
add
(
e2
);
colection
.
add
(
e3
);
Gson
gson
=
new
Gson
();
String
json_represntation
=
gson
.
toJson
(
colection
);
System
.
out
.
print
(
"Representación : \n"
+
json_represntation
);
System
.
out
.
print
(
json_represntation
);
// al revés, pero más complicado
// procesar un mensaje recibido con JSON, en el que no solo hay tipos Empoyee
...
...
@@ -292,6 +299,7 @@ public class TestJSON {
String
json_recibido2
=
"[{\"firstName\":\"John\", \"lastName\":\"Doe\"},{\"firstName\":\"Anna\", \"lastName\":\"Smith\"},{\"firstName\":\"Peter\", \"lastName\": \"Jones\"}]"
;
HashMap
<
String
,
Object
>
mensaje
=
gson
.
fromJson
(
json_recibido
,
jType
);
System
.
out
.
println
(
" ----- "
);
System
.
out
.
println
(
mensaje
.
get
(
"mensaje"
));
System
.
out
.
println
(
mensaje
.
get
(
"id"
));
...
...
@@ -307,11 +315,12 @@ public class TestJSON {
}
public
static
void
main
(
String
args
[])
{
new
TestJSON
();
}
public
static
void
main
(
String
args
[])
{
new
TestJSON
();
}
}
```
Crea la clase Employee.java:
...
...
@@ -322,10 +331,9 @@ public class Employee {
public
String
firstName
;
public
String
lastName
;
public
Employee
(
String
firstName
,
String
lastName
)
{
super
();
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
public
Employee
()
{
// TODO Auto-generated constructor stub
}
public
String
toString
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment