<commit_before>package com.blinkbox.books.auth.server

import org.joda.time.DateTime
import org.json4s.JsonAST.{JString, JField, JObject}
import org.json4s.ext.{JodaTimeSerializers, EnumNameSerializer}
import org.json4s._
import JsonDSL._
import spray.httpx.Json4sJacksonSupport

object ZuulRequestExceptionSerializer extends Serializer[ZuulRequestException] {
  override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), ZuulRequestException] = {

    case (_, JObject(
    JField("error", JString(code)) :: JField("error_reason", JString(reason)) :: JField("error_description", JString(message)) :: Nil
    )) => ZuulRequestException(message, ZuulRequestErrorCode.fromString(code), Some(ZuulRequestErrorReason.fromString(reason)))

    case (_, JObject(
    JField("error", JString(code)) :: JField("error_description", JString(message)) :: Nil
    )) => ZuulRequestException(message, ZuulRequestErrorCode.fromString(code), None)
  }

  override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
    case e: ZuulRequestException =>
      ("error" -> ZuulRequestErrorCode.toString(e.code)) ~
        ("error_reason" -> e.reason.map(ZuulRequestErrorReason.toString)) ~
        ("error_description" -> e.message)
  }
}

object Serialization extends Json4sJacksonSupport {
  val clientInfoSerializer = FieldSerializer[ClientInfo](
    serializer = {
      case ("last_used_date", d) => Some("last_used_date", d.asInstanceOf[DateTime].toString("yyyy-MM-dd"))
    }
  )

  implicit def json4sJacksonFormats: Formats = (DefaultFormats + ZuulRequestExceptionSerializer +
    new EnumNameSerializer(RefreshTokenStatus) + clientInfoSerializer) ++ JodaTimeSerializers.all
}<commit_msg>Drop JodaSerializers in favour if ISODateTimeSerializer<commit_after>package com.blinkbox.books.auth.server

import com.blinkbox.books.spray.JsonFormats.ISODateTimeSerializer
import org.joda.time.DateTime
import org.json4s.JsonAST.{JString, JField, JObject}
import org.json4s.ext.{JodaTimeSerializers, EnumNameSerializer}
import org.json4s._
import JsonDSL._
import spray.httpx.Json4sJacksonSupport

object ZuulRequestExceptionSerializer extends Serializer[ZuulRequestException] {
  override def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), ZuulRequestException] = {

    case (_, JObject(
    JField("error", JString(code)) :: JField("error_reason", JString(reason)) :: JField("error_description", JString(message)) :: Nil
    )) => ZuulRequestException(message, ZuulRequestErrorCode.fromString(code), Some(ZuulRequestErrorReason.fromString(reason)))

    case (_, JObject(
    JField("error", JString(code)) :: JField("error_description", JString(message)) :: Nil
    )) => ZuulRequestException(message, ZuulRequestErrorCode.fromString(code), None)
  }

  override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
    case e: ZuulRequestException =>
      ("error" -> ZuulRequestErrorCode.toString(e.code)) ~
        ("error_reason" -> e.reason.map(ZuulRequestErrorReason.toString)) ~
        ("error_description" -> e.message)
  }
}

object Serialization extends Json4sJacksonSupport {
  val clientInfoSerializer = FieldSerializer[ClientInfo](
    serializer = {
      case ("last_used_date", d) => Some("last_used_date", d.asInstanceOf[DateTime].toString("yyyy-MM-dd"))
    }
  )

  implicit def json4sJacksonFormats: Formats = DefaultFormats + ZuulRequestExceptionSerializer +
    new EnumNameSerializer(RefreshTokenStatus) + clientInfoSerializer + ISODateTimeSerializer
}
{'fraction_non_alphanumeric': 0.11822521763549565, 'fraction_numerical': 0.003369839932603201, 'mean_word_length': 5.929961089494164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '2014864', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1074, 'n_words': 187}