Skip to content

Commit

Permalink
#3033 Fixed HttpMessageNotWritableException:
Browse files Browse the repository at this point in the history
- Added serializers: ChronologySerializer, LocalDateTimeSerializer;
- Corrected package for SnippetContentGenerator, SnippetServletResponse (from org.scada_lts.web.contnet to org.scada_lts.web.content);
  • Loading branch information
Limraj committed Oct 20, 2024
1 parent e68fcd1 commit 55cd3f5
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
2 changes: 2 additions & 0 deletions WebContent/WEB-INF/springDispatcher-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
<array>
<bean class="org.scada_lts.web.security.XssProtectStringSerializer" />
<bean class="org.scada_lts.web.security.XssProtectCssStyleSerializer" />
<bean class="org.scada_lts.web.beans.serializer.ChronologySerializer" />
<bean class="org.scada_lts.web.beans.serializer.LocalDateTimeSerializer" />
</array>
</property>
</bean>
Expand Down
2 changes: 1 addition & 1 deletion src/com/serotonin/mango/web/dwr/BaseDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.scada_lts.mango.adapter.MangoEvent;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;

abstract public class BaseDwr {
public static final String MODEL_ATTR_EVENTS = "events";
Expand Down
24 changes: 24 additions & 0 deletions src/org/scada_lts/web/beans/serializer/ChronologySerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.scada_lts.web.beans.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.chrono.Chronology;


public class ChronologySerializer extends StdSerializer<Chronology> {

public ChronologySerializer() {
super(Chronology.class);
}

@Override
public void serialize(Chronology value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
jgen.writeStringField("id", value.getId());
jgen.writeStringField("calendarType", value.getCalendarType());
jgen.writeEndObject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.scada_lts.web.beans.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.LocalDateTime;


public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {

public LocalDateTimeSerializer() {
super(LocalDateTime.class);
}

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
jgen.writeNumberField("nano", value.getNano());
jgen.writeNumberField("year", value.getYear());
jgen.writeNumberField("monthValue", value.getMonthValue());
jgen.writeNumberField("dayOfMonth", value.getDayOfMonth());
jgen.writeNumberField("hour", value.getHour());
jgen.writeNumberField("minute", value.getMinute());
jgen.writeNumberField("second", value.getSecond());
jgen.writeStringField("month", value.getMonth().name());
jgen.writeStringField("dayOfWeek", value.getDayOfWeek().name());
jgen.writeNumberField("dayOfYear", value.getDayOfYear());
jgen.writeObjectField("chronology", value.getChronology());
jgen.writeEndObject();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.web.contnet;
package org.scada_lts.web.content;

import java.io.IOException;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.web.contnet;
package org.scada_lts.web.content;

import java.io.IOException;
import java.io.PrintWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.scada_lts.dao.SystemSettingsDAO;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;
import org.springframework.mock.web.MockHttpSession;
import utils.TestConcurrentUtils;
import utils.mock.EventServiceMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.scada_lts.dao.SystemSettingsDAO;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.ViewService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;
import org.springframework.mock.web.MockHttpSession;
import utils.*;
import utils.mock.ChangePointValueDataPointRtMock;
Expand Down

0 comments on commit 55cd3f5

Please sign in to comment.