<commit_before>package uk.ac.ox.ndm.grails.utils.marshalling

import grails.converters.JSON
import grails.converters.XML

import javax.annotation.PostConstruct
import javax.xml.datatype.DatatypeFactory
import java.time.LocalDate
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter

/**
 * @since 22/09/2015
 */
class MarshallerRegistrar {

    @PostConstruct
    def registerJavaCoreMarshallers() {
        XML.registerObjectMarshaller(LocalDate) {
            it?.format(DateTimeFormatter.ISO_DATE)
        }

        XML.registerObjectMarshaller(OffsetDateTime) {
            it?.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
        }

        XML.registerObjectMarshaller(UUID) {
            it?.toString()
        }

        XML.registerObjectMarshaller(Date) {Date dt ->
            GregorianCalendar calendar = new GregorianCalendar()
            calendar.setTime(dt)
            DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toString()
        }

        JSON.registerObjectMarshaller(LocalDate) {
            it?.toString()
        }<commit_msg>Fix marshalled offsetdatetime to UTC<commit_after>package uk.ac.ox.ndm.grails.utils.marshalling

import grails.converters.JSON
import grails.converters.XML

import javax.annotation.PostConstruct
import javax.xml.datatype.DatatypeFactory
import java.time.LocalDate
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

/**
 * @since 22/09/2015
 */
class MarshallerRegistrar {

    @PostConstruct
    def registerJavaCoreMarshallers() {
        XML.registerObjectMarshaller(LocalDate) {
            it?.format(DateTimeFormatter.ISO_DATE)
        }

        XML.registerObjectMarshaller(OffsetDateTime) {OffsetDateTime odt ->
            odt.withOffsetSameInstant(ZoneOffset.UTC).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
        }

        XML.registerObjectMarshaller(UUID) {
            it?.toString()
        }

        XML.registerObjectMarshaller(Date) {Date dt ->
            GregorianCalendar calendar = new GregorianCalendar()
            calendar.setTime(dt)
            DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toString()
        }

        JSON.registerObjectMarshaller(LocalDate) {
            it?.toString()
        }
{'fraction_non_alphanumeric': 0.0891304347826087, 'fraction_numerical': 0.006956521739130435, 'mean_word_length': 3.022727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1223858', 'n_tokens_mistral': 653, 'n_tokens_neox': 632, 'n_words': 88}