Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Rename @snakecase to @JsonSnakeCase.
Browse files Browse the repository at this point in the history
Otherwise it looks pretty damn odd.
  • Loading branch information
codahale committed Sep 17, 2011
1 parent 8c8bcf6 commit 2edea1c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.codahale.jerkson;

import org.codehaus.jackson.annotate.JacksonAnnotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -12,6 +14,7 @@
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface SnakeCase {
@JacksonAnnotation
public @interface JsonSnakeCase {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.codahale.jerkson.deser

import scala.collection.JavaConversions._
import scala.collection.mutable.ArrayBuffer
import com.codahale.jerkson.SnakeCase
import com.codahale.jerkson.JsonSnakeCase
import com.codahale.jerkson.util._
import com.codahale.jerkson.Util._
import org.codehaus.jackson.{JsonNode, JsonToken, JsonParser}
Expand All @@ -16,7 +16,7 @@ class CaseClassDeserializer(config: DeserializationConfig,
javaType: JavaType,
provider: DeserializerProvider,
classLoader: ClassLoader) extends JsonDeserializer[Object] {
private val isSnakeCase = javaType.getRawClass.isAnnotationPresent(classOf[SnakeCase])
private val isSnakeCase = javaType.getRawClass.isAnnotationPresent(classOf[JsonSnakeCase])
private val params = CaseClassSigParser.parse(javaType.getRawClass, config.getTypeFactory, classLoader).map { case (name, jt) =>
(if (isSnakeCase) snakeCase(name) else name, jt)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.codahale.jerkson.ser

import java.lang.reflect.Modifier
import com.codahale.jerkson.SnakeCase
import com.codahale.jerkson.JsonSnakeCase
import com.codahale.jerkson.Util._
import org.codehaus.jackson.JsonGenerator
import org.codehaus.jackson.annotate.{JsonIgnore, JsonIgnoreProperties}
Expand All @@ -10,7 +10,7 @@ import org.codehaus.jackson.map.annotate.JsonCachable

@JsonCachable
class CaseClassSerializer[A <: Product](klass: Class[_]) extends JsonSerializer[A] {
private val isSnakeCase = klass.isAnnotationPresent(classOf[SnakeCase])
private val isSnakeCase = klass.isAnnotationPresent(classOf[JsonSnakeCase])
private val ignoredFields = if (klass.isAnnotationPresent(classOf[JsonIgnoreProperties])) {
klass.getAnnotation(classOf[JsonIgnoreProperties]).value().toSet
} else Set.empty[String]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.codahale.jerkson.tests

import org.codehaus.jackson.JsonNode
import org.codehaus.jackson.annotate.{JsonIgnoreProperties, JsonIgnore}
import com.codahale.jerkson.SnakeCase
import com.codahale.jerkson.JsonSnakeCase

case class CaseClass(id: Long, name: String)

Expand Down Expand Up @@ -68,5 +68,5 @@ case class CaseClassWithTwoConstructors(id: Long, name: String) {
def this(id: Long) = this(id, "New User")
}

@SnakeCase
@JsonSnakeCase
case class CaseClassWithSnakeCase(oneThing: String, twoThing: String)

0 comments on commit 2edea1c

Please sign in to comment.