<commit_before>package de.innoaccel.wamp.server.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.innoaccel.wamp.server.Websocket;
import de.innoaccel.wamp.server.message.EventMessage;
import de.innoaccel.wamp.server.message.Message;

public class EventMessageConverter extends JsonParsingConverter<EventMessage>
{
    public  EventMessageConverter()
    {
        this(new ObjectMapper());
    }

    public EventMessageConverter(ObjectMapper objectMapper)
    {
        super(objectMapper);
    }

    @Override
    public boolean canConvert(int messageCode)
    {
        return Message.EVENT == messageCode;
    }

    @Override
    public String serialize(EventMessage message, Websocket socket) throws InvalidMessageCodeException
    {
        try {
            return this.objectMapper.writeValueAsString(new Object[] {
                    Message.EVENT,
                    message.getTopicURI(),
                    message.getPayload()
            });
        } catch (JsonProcessingException ex) {
            throw new InvalidMessageCodeException(Message.EVENT);
        }
    }

    protected EventMessage deserialize(JsonNode rootNode, Websocket socket) throws MessageParseException, InvalidMessageCodeException
    {
        this.assertMessageCode(rootNode, Message.EVENT);

        String topic = this.readStringAt(rootNode, 1);
        if (0 == topic.length()) {
            throw new MessageParseException("Message has invalid markup (topic is not valid)");
        }
        // TODO: can we formulate further contraints for the payload? Provide tests about the content?

        return new EventMessage(socket.inflateCURI(topic), this.readAnyTypeAt(rootNode, 2));
    }
}<commit_msg>Update to use new base method<commit_after>package de.innoaccel.wamp.server.converter;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.innoaccel.wamp.server.Websocket;
import de.innoaccel.wamp.server.message.EventMessage;
import de.innoaccel.wamp.server.message.Message;

public class EventMessageConverter extends JsonParsingConverter<EventMessage>
{
    public  EventMessageConverter()
    {
        this(new ObjectMapper());
    }

    public EventMessageConverter(ObjectMapper objectMapper)
    {
        super(objectMapper);
    }

    @Override
    public boolean canConvert(int messageCode)
    {
        return Message.EVENT == messageCode;
    }

    @Override
    public String serialize(EventMessage message, Websocket socket) throws InvalidMessageCodeException
    {
        try {
            return this.objectMapper.writeValueAsString(new Object[] {
                    Message.EVENT,
                    message.getTopicURI(),
                    message.getPayload()
            });
        } catch (JsonProcessingException ex) {
            throw new InvalidMessageCodeException(Message.EVENT);
        }
    }

    protected EventMessage deserialize(JsonNode rootNode, Websocket socket) throws MessageParseException, InvalidMessageCodeException
    {
        this.assertMessageCode(rootNode, Message.EVENT);

        String topic = this.readStringAt(rootNode, 1);
        if (0 == topic.length()) {
            throw new MessageParseException("Message has invalid markup (topic is not valid)");
        }
        // TODO: can we formulate further contraints for the payload? Provide tests about the content?

        return new EventMessage(socket.inflateCURI(topic), this.readAnyAt(rootNode, 2));
    }
}
{'fraction_non_alphanumeric': 0.08319738988580751, 'fraction_numerical': 0.0016313213703099511, 'mean_word_length': 3.0339912280701755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5454061', 'n_tokens_mistral': 989, 'n_tokens_neox': 939, 'n_words': 213}