Commit 145f89e6 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

First attempt at modularization

parent 8f92af97
module todolist.core {
requires transitive com.fasterxml.jackson.databind;
exports todolist.core;
exports todolist.json;
}
package todolist.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
......@@ -9,7 +12,10 @@ import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import todolist.core.TodoModel;
import todolist.json.internal.TodoModule;
/**
* Wrapper class for JSON serialization,
......@@ -20,8 +26,16 @@ public class TodoPersistence {
private ObjectMapper mapper;
public TodoPersistence() {
mapper = new ObjectMapper();
mapper.registerModule(new TodoModule());
mapper = createObjectMapper();
}
public static SimpleModule createJacksonModule(boolean deep) {
return new TodoModule(deep);
}
public static ObjectMapper createObjectMapper() {
return new ObjectMapper()
.registerModule(createJacksonModule(true));
}
public TodoModel readTodoModel(Reader reader) throws IOException {
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.module.SimpleModule;
......
......@@ -14,6 +14,7 @@ import todolist.core.AbstractTodoList;
import todolist.core.TodoItem;
import todolist.core.TodoList;
import todolist.core.TodoModel;
import todolist.json.internal.TodoModule;
public class TodoModuleTest {
......
module todolist.ui {
requires com.fasterxml.jackson.databind;
requires java.net.http;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires todolist.core;
requires fxutil;
opens todolist.ui to javafx.graphics, javafx.fxml;
}
......@@ -14,7 +14,7 @@ import java.util.Collection;
import todolist.core.AbstractTodoList;
import todolist.core.TodoList;
import todolist.core.TodoModel;
import todolist.json.TodoModule;
import todolist.json.TodoPersistence;
/**
* Class that centralizes access to a TodoModel. Makes it easier to support transparent use of a
......@@ -30,7 +30,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
public RemoteTodoModelAccess(URI endpointBaseUri) {
this.endpointBaseUri = endpointBaseUri;
objectMapper = new ObjectMapper().registerModule(new TodoModule());
objectMapper = TodoPersistence.createObjectMapper();
}
private TodoModel getTodoModel() {
......@@ -44,7 +44,6 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
final String responseString = response.body();
this.todoModel = objectMapper.readValue(responseString, TodoModel.class);
System.out.println("TodoModel: " + this.todoModel);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
......
module fxutil {
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
exports fxutil.doc;
opens fxutil to javafx.graphics, javafx.fxml;
}
......@@ -12,8 +12,8 @@
<artifactId>rest</artifactId>
<properties>
<slf4jVersion>1.7.25</slf4jVersion>
<jerseyVersion>3.0.1</jerseyVersion>
<slf4jVersion>2.0.0-alpha5</slf4jVersion>
<jerseyVersion>3.0.3</jerseyVersion>
</properties>
<dependencies>
......@@ -170,6 +170,11 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens todolist.rest/todolist.restapi=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<!-- Run the checkstyle code quality tool -->
<plugin>
......
module todolist.rest {
requires jakarta.ws.rs;
requires jersey.common;
requires jersey.server;
requires jersey.media.json.jackson;
requires org.glassfish.hk2.api;
requires org.slf4j;
requires todolist.core;
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.Provider;
import todolist.json.TodoModule;
import todolist.json.TodoPersistence;
/**
* Provides the Jackson module used for JSON serialization.
......@@ -19,7 +19,7 @@ public class TodoModuleObjectMapperProvider implements ContextResolver<ObjectMap
private final ObjectMapper objectMapper;
public TodoModuleObjectMapperProvider() {
objectMapper = new ObjectMapper().registerModule(new TodoModule(false));
objectMapper = TodoPersistence.createObjectMapper();
}
@Override
......
......@@ -23,7 +23,7 @@ import todolist.restapi.TodoModelService;
public class TodoServiceTest extends JerseyTest {
protected boolean shouldLog() {
return false;
return true;
}
@Override
......
module todolist.springboot.rest {
requires com.fasterxml.jackson.databind;
requires spring.web;
requires spring.boot;
requires todolist.core;
}
......@@ -4,14 +4,16 @@ import com.fasterxml.jackson.databind.Module;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import todolist.json.TodoModule;
import todolist.json.TodoPersistence;
import todolist.json.internal.TodoModule;
@SpringBootApplication
public class TodoModelApplication {
@Bean
public Module objectMapperModule() {
return new TodoModule(false);
return TodoPersistence.createJacksonModule(false);
}
public static void main(String[] args) {
......
......@@ -20,7 +20,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import todolist.core.AbstractTodoList;
import todolist.core.TodoModel;
import todolist.json.TodoModule;
import todolist.json.TodoPersistence;
@AutoConfigureMockMvc
@ContextConfiguration(classes = { TodoModelController.class, TodoModelService.class, TodoModelApplication.class })
......@@ -34,7 +34,7 @@ public class TodoModelApplicationTest {
@BeforeEach
public void setup() throws Exception {
objectMapper = new ObjectMapper().registerModule(new TodoModule(false));;
objectMapper = TodoPersistence.createObjectMapper();
}
private String todoUrl(String... segments) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment