Skip to content

Commit

Permalink
fixing scala bundle toJsonBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenCepoi committed Jul 23, 2014
1 parent 11d3dd7 commit af22196
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions genson-scala/src/main/scala/com/owlike/genson/ScalaGenson.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.owlike.genson

import java.lang.reflect.{Type => JType, ParameterizedType}
import java.io.{OutputStream, Writer, InputStream, StringReader, Reader => JReader}
import java.io.{Reader => JReader, _}
import java.net.URL

import com.owlike.genson.reflect.TypeUtil._
Expand All @@ -11,7 +11,13 @@ class ScalaGenson(val genson: Genson) extends AnyVal {

def toJson[T: Manifest](value: T): String = genson.serialize(value, GenericType.of(toJavaType))

def toJsonBytes[T: Manifest](value: T): Array[Byte] = genson.serializeBytes(value, GenericType.of(toJavaType))
def toJsonBytes[T: Manifest](value: T): Array[Byte] = {
val baos = new ByteArrayOutputStream()
val objectWriter = genson.createWriter(baos)

genson.serialize(value, toJavaType, objectWriter, new Context(genson))
baos.toByteArray()
}

def toJson[T: Manifest](value: T, writer: Writer): Unit = toJson(value, genson.createWriter(writer))

Expand Down

0 comments on commit af22196

Please sign in to comment.