Java Reference
In-Depth Information
private
private
String lastName
;
public
public
int
int
getId
() {
return
return
id
;
}
public
public
void
void
setId
(
int
int
id
) {
this
this
.
id
=
id
;
}
public
public
String
getFirstName
() {
return
return
firstName
;
}
public
public
void
void
setFirstName
(
String firstName
) {
this
this
.
firstName
=
firstName
;
}
public
public
String
getLastName
() {
return
return
lastName
;
}
public
public
void
void
setLastName
(
String lastName
) {
this
this
.
lastName
=
lastName
;
}
}
and sample data:
{
"id"
"id"
:
42
,
"firstName"
"firstName"
:
"Bill"
,
"lastName"
"lastName"
:
"Burke"
}
reading in the data to create a
Customer
object would be as easy as this:
ObjectMapper mapper
=
new
new
ObjectMapper
();
Customer cust
=
mapper
.
readValue
(
inputStream
,
Customer
.
class
);
Writing the data would be as easy as this:
ObjectMapper mapper
=
new
new
ObjectMapper
();
mapper
.
writeValue
(
outputStream
,
customer
);