-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid reparsing numbers when serializing
- Loading branch information
Showing
2 changed files
with
45 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
play-json/jvm/src/main/scala/play/api/libs/json/jackson/StringBasedNumericNode.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com> | ||
*/ | ||
|
||
package play.api.libs.json.jackson | ||
|
||
import com.fasterxml.jackson.core.{JsonGenerator, JsonParser, JsonToken} | ||
import com.fasterxml.jackson.databind.SerializerProvider | ||
import com.fasterxml.jackson.databind.node.NumericNode | ||
|
||
import java.math.{BigDecimal, BigInteger} | ||
|
||
/** | ||
* A numeric node that is represented as a string. | ||
* | ||
* For internal use only. Some methods are not implemented and will throw an exception. | ||
*/ | ||
private[jackson] case class StringBasedNumericNode(text : String) extends NumericNode { | ||
|
||
override def numberType = JsonParser.NumberType.BIG_DECIMAL | ||
|
||
override def asText(): String = text | ||
|
||
override def asToken(): JsonToken = JsonToken.VALUE_NUMBER_FLOAT | ||
|
||
override def serialize(jgen: JsonGenerator, ctxt: SerializerProvider): Unit = | ||
jgen.writeNumber(text) | ||
|
||
override def numberValue: Number = throw new NotImplementedError | ||
|
||
override def intValue: Int = throw new NotImplementedError | ||
|
||
override def longValue: Long = throw new NotImplementedError | ||
|
||
override def doubleValue: Double = throw new NotImplementedError | ||
|
||
override def decimalValue: BigDecimal = throw new NotImplementedError | ||
|
||
override def bigIntegerValue: BigInteger = throw new NotImplementedError | ||
|
||
override def canConvertToInt: Boolean = false | ||
|
||
override def canConvertToLong: Boolean = false | ||
} |