<commit_before>package com.openxc.measurements.serializers;

import java.io.IOException;
import java.io.StringWriter;

import java.text.DecimalFormat;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;

import android.util.Log;

public class JsonSerializer implements MeasurementSerializer {
    private static final String TAG = "JsonSerializer";
    public static final String NAME_FIELD = "name";
    public static final String VALUE_FIELD = "value";
    public static final String EVENT_FIELD = "event";
    public static final String TIMESTAMP_FIELD = "timestamp";
    private static DecimalFormat sTimestampFormatter =
            new DecimalFormat("##########.000000");

    public static String serialize(String name, Object value, Object event,
            Double timestamp) {
        StringWriter buffer = new StringWriter(64);
        JsonFactory jsonFactory = new JsonFactory();
        try {
            JsonGenerator gen = jsonFactory.createJsonGenerator(buffer);

            gen.writeStartObject();
            gen.writeStringField(NAME_FIELD, name);

            if(value != null) {
                gen.writeObjectField(VALUE_FIELD, value);
            }

            if(event != null) {
                gen.writeObjectField(EVENT_FIELD, event);
            }

            if(timestamp != null) {
                gen.writeNumberField(TIMESTAMP_FIELD, timestamp);
            }

            gen.writeEndObject();
            gen.close();
        } catch(IOException e) {
            Log.w(TAG, "Unable to encode all data to JSON -- " +
                    "message may be incomplete", e);
        }
        return buffer.toString();
    }
}<commit_msg>Use correct timestamp format in serialized JSON.<commit_after>package com.openxc.measurements.serializers;

import java.io.IOException;
import java.io.StringWriter;

import java.text.DecimalFormat;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;

import android.util.Log;

public class JsonSerializer implements MeasurementSerializer {
    private static final String TAG = "JsonSerializer";
    public static final String NAME_FIELD = "name";
    public static final String VALUE_FIELD = "value";
    public static final String EVENT_FIELD = "event";
    public static final String TIMESTAMP_FIELD = "timestamp";
    private static DecimalFormat sTimestampFormatter =
            new DecimalFormat("##########.000000");

    public static String serialize(String name, Object value, Object event,
            Double timestamp) {
        StringWriter buffer = new StringWriter(64);
        JsonFactory jsonFactory = new JsonFactory();
        try {
            JsonGenerator gen = jsonFactory.createJsonGenerator(buffer);

            gen.writeStartObject();
            gen.writeStringField(NAME_FIELD, name);

            if(value != null) {
                gen.writeObjectField(VALUE_FIELD, value);
            }

            if(event != null) {
                gen.writeObjectField(EVENT_FIELD, event);
            }

            if(timestamp != null) {
                gen.writeFieldName(TIMESTAMP_FIELD);
                gen.writeRawValue(sTimestampFormatter.format(timestamp));
            }

            gen.writeEndObject();
            gen.close();
        } catch(IOException e) {
            Log.w(TAG, "Unable to encode all data to JSON -- " +
                    "message may be incomplete", e);
        }
        return buffer.toString();
    }
}
{'fraction_non_alphanumeric': 0.09335981838819524, 'fraction_numerical': 0.004540295119182747, 'mean_word_length': 2.4423828125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1921238', 'n_tokens_mistral': 912, 'n_tokens_neox': 855, 'n_words': 230}