<commit_before>package org.jeeventstore.serialization.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import org.jeeventstore.core.serialization.EventSerializer;

/**
 * An EventSerializer implementation using Google's Gson library.
 * @author <NAME>
 */
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class EventSerializerGson implements EventSerializer {

    private static final Logger log = Logger.getLogger(EventSerializerGson.class.getName());

    private Gson gson;

    /*
     * This searches the class path and lists all custom converters.
     */
    @Inject
    private Instance<EventSerializerGsonTypeConverter> typeConverters;

    @PostConstruct
    public void init() {
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(EventList.class, new EventListTypeConverter());

        Iterator<EventSerializerGsonTypeConverter> convit = typeConverters.iterator();
        while (convit.hasNext()) {
            EventSerializerGsonTypeConverter conv = convit.next();
            log.log(Level.INFO, "Registering type converter for class {0}",
                    conv.convertedType().getCanonicalName());
            builder.registerTypeAdapter(conv.convertedType(), conv);
        }

        this.gson = builder.create();
    }

    @Override
    @Lock(LockType.READ)
    public String serialize(List<? extends Serializable> events) {
        EventList evlist = new EventList(events);
        return gson.toJson(evlist);
    }

    @Override
    @Lock(LockType.READ)
    public List<? extends Serializable> deserialize(String body) {
        return this.gson.fromJson(body, EventList.class).events();
    }

}<commit_msg>Make EventStoreGson use container managed locking.<commit_after>package org.jeeventstore.serialization.gson;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import org.jeeventstore.core.serialization.EventSerializer;

/**
 * An EventSerializer implementation using Google's Gson library.
 * @author <NAME>
 */
public class EventSerializerGson implements EventSerializer {

    private static final Logger log = Logger.getLogger(EventSerializerGson.class.getName());

    private Gson gson;

    /*
     * This searches the class path and lists all custom converters.
     */
    @Inject
    private Instance<EventSerializerGsonTypeConverter> typeConverters;

    @PostConstruct
    public void init() {
        GsonBuilder builder = new GsonBuilder();
        builder.registerTypeAdapter(EventList.class, new EventListTypeConverter());

        // register client's type adapters
        Iterator<EventSerializerGsonTypeConverter> convit = typeConverters.iterator();
        while (convit.hasNext()) {
            EventSerializerGsonTypeConverter conv = convit.next();
            log.log(Level.INFO, "Registering type converter for class {0}",
                    conv.convertedType().getCanonicalName());
            builder.registerTypeAdapter(conv.convertedType(), conv);
        }
        this.gson = builder.create();
    }

    @Override
    @Lock(LockType.READ)
    public String serialize(List<? extends Serializable> events) {
        EventList evlist = new EventList(events);
        return gson.toJson(evlist);
    }

    @Override
    @Lock(LockType.READ)
    public List<? extends Serializable> deserialize(String body) {
        return this.gson.fromJson(body, EventList.class).events();
    }

}
{'fraction_non_alphanumeric': 0.0984958757884522, 'fraction_numerical': 0.00048520135856380397, 'mean_word_length': 3.690557451649602, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '380524', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1125, 'n_words': 256}