[JAVA-13854] Half list moved (#12598)

* [JAVA-13854] added parent module

* [JAVA-13854] moved apache-tapestry(submodule) to web-modules(parent)

* [JAVA-13854] moved bootique(submodule) to web-modules(parent)

* [JAVA-13854] moved dropwizard(submodule) to web-modules(parent)

* [JAVA-13854] moved blade(submodule) to web-modules(parent)

* [JAVA-13854] moved java-lite(submodule) to web-modules(parent)

* [JAVA-13854] moved jooby(submodule) to web-modules(parent)

* [JAVA-13854] moved linkrest(submodule) to web-modules(parent)

* [JAVA-13854] moved ninja(submodule) to web-modules(parent)

* [JAVA-13854] moved ratpack(submodule) to web-modules(parent)

* [JAVA-13854] moved resteasy(submodule) to web-modules(parent)

* [JAVA-13854] moved restx(submodule) to web-modules(parent)

* [JAVA-13854] moved spark-java(submodule) to web-modules(parent)

* [JAVA-13854] moved vraptor(submodule) to web-modules(parent)

* [JAVA-13854] delete modules that were moved

* [JAVA-13854]

* [JAVA-13854]

* [JAVA-13854] delete ninja submodule  + moved raml(submodule) to web-modules(parent)

* [JAVA-13854] moved gwt(submodule) to web-modules(parent)

* [JAVA-13854] moved jakarta-ee(submodule) to web-modules(parent)

* [JAVA-13854] moved javax-servlets(submodule) to web-modules(parent)

* [JAVA-13854] moved javax-servlets-2(submodule) to web-modules(parent)

* [JAVA-13854] moved jee-7(submodule) to web-modules(parent)

* [JAVA-13854] moved play-framework(not a module) to web-modules

* [JAVA-13854] fix failing test

* [JAVA-13854] moved struts-2(submodule) to web-modules(parent)

* [JAVA-13854] moved wicket(submodule) to web-modules(parent)

* [JAVA-13854] deleted modules that were moved to web-modules

* JAVA-13854 Removed moved modules from the main pom.xml

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
Co-authored-by: Dhawal Kapil <dhawalkapil@gmail.com>
This commit is contained in:
panos-kakos
2022-08-21 10:14:00 +01:00
committed by GitHub
parent 842a71ad92
commit 0b9549bd3e
755 changed files with 768 additions and 755 deletions
@@ -0,0 +1,43 @@
package com.baeldung.json;
import java.util.Date;
import java.util.List;
public class Person {
private String firstName;
private String lastName;
private Date birthdate;
private List<String> emails;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Date getBirthdate() {
return birthdate;
}
public void setBirthdate(Date birthdate) {
this.birthdate = birthdate;
}
public List<String> getEmails() {
return emails;
}
public void setEmails(List<String> emails) {
this.emails = emails;
}
}
@@ -0,0 +1,42 @@
package com.baeldung.json;
import javax.json.*;
import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.stream.Collectors;
public class PersonBuilder {
private String jsonString;
private SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
public PersonBuilder(String jsonString) {
this.jsonString = jsonString;
}
public Person build() throws IOException, ParseException {
JsonReader reader = Json.createReader(new StringReader(jsonString));
JsonObject jsonObject = reader.readObject();
Person person = new Person();
person.setFirstName(jsonObject.getString("firstName"));
person.setLastName(jsonObject.getString("lastName"));
person.setBirthdate(dateFormat.parse(jsonObject.getString("birthdate")));
JsonArray emailsJson = jsonObject.getJsonArray("emails");
List<String> emails = emailsJson.getValuesAs(JsonString.class).stream()
.map(JsonString::getString)
.collect(Collectors.toList());
person.setEmails(emails);
return person;
}
}
@@ -0,0 +1,60 @@
package com.baeldung.json;
import javax.json.*;
import javax.json.stream.JsonGenerator;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
public class PersonWriter {
private Person person;
private SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
public PersonWriter(Person person) {
this.person = person;
}
public String write() throws IOException {
JsonObjectBuilder objectBuilder = Json
.createObjectBuilder()
.add("firstName", person.getFirstName())
.add("lastName", person.getLastName())
.add("birthdate", dateFormat.format(person.getBirthdate()));
final JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
person.getEmails().forEach(arrayBuilder::add);
objectBuilder.add("emails", arrayBuilder);
JsonObject jsonObject = objectBuilder.build();
JsonWriterFactory writerFactory = createWriterFactory();
return writeToString(jsonObject, writerFactory);
}
private String writeToString(JsonObject jsonObject, JsonWriterFactory writerFactory) throws IOException {
String jsonString;
try (Writer writer = new StringWriter()) {
writerFactory
.createWriter(writer)
.write(jsonObject);
jsonString = writer.toString();
}
return jsonString;
}
private JsonWriterFactory createWriterFactory() {
Map<String, Boolean> config = new HashMap<>();
config.put(JsonGenerator.PRETTY_PRINTING, true);
return Json.createWriterFactory(config);
}
}