I am running a web application using Jersey. In my controller, I am trying to get a file in resources and also return an object which contains an enum. I am getting errors at both of these steps.
- When the file is being fetched, I am getting a
java.io.FileNotFoundException: src\main\resources\tsv\ProductValid.tsv (The system cannot find the path specified) - When the object is being marshalled, I am getting errors:
jakarta.xml.bind.JAXBException: Implementation of Jakarta XML Binding-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
and
[Exception [EclipseLink-50001] (Eclipse Persistence Services - 3.0.0.v202012081010): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class com.jtv.insights.tool.model.IngestionLogs requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.]
Jul 14, 2021 11:15:17 AM org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo
SEVERE: MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=java.util.List<com.jtv.insights.tool.model.IngestionLogs>.
My folder structure is:
My gradle dependencies are:
dependencies {
implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: '3.0.2'
implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '3.0.2'
implementation group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '3.0.2'
}
My code is:
@GET
@Path(value = "/log/details/{fileId}")
@Produces(MediaType.APPLICATION_JSON)
public List<IngestionLogs> getIngestionLogDetails(@PathParam("fileId") String fileId) {
List<IngestionLogs> logs = new ArrayList<>();
try {
String key = "Physical/STP_20201214.tsv";
File file = new File("src/main/resources/tsv/ProductValid.tsv");
InputStream stream = new FileInputStream(file);
List<IngestionLogs> errors = TsvFileValidators.parseObject(stream);
logs.addAll(errors);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("eclipselink.media-type", "application/json");
JAXBContext ctx = JAXBContext.newInstance(new Class[] { IngestionLogs.class }, properties);
Marshaller jsonMarshaller = ctx.createMarshaller();
jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
jsonMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jsonMarshaller.marshal(logs, System.out);
} catch (JAXBException e) {
e.printStackTrace();
}
return logs;
}
How do I fix these two errors?