Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Fastjson
Commits
9a07dc1e
Commit
9a07dc1e
authored
7 years ago
by
wenshao
Browse files
Options
Download
Email Patches
Plain Diff
improved parse Currency
parent
be0dd7ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/alibaba/fastjson/serializer/MiscCodec.java
+21
-9
src/main/java/com/alibaba/fastjson/serializer/MiscCodec.java
src/test/java/com/alibaba/json/bvt/CurrencyTest4.java
+37
-0
src/test/java/com/alibaba/json/bvt/CurrencyTest4.java
with
58 additions
and
9 deletions
+58
-9
src/main/java/com/alibaba/fastjson/serializer/MiscCodec.java
+
21
-
9
View file @
9a07dc1e
...
...
@@ -9,17 +9,10 @@ import java.net.URI;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.text.SimpleDateFormat
;
import
java.util.Currency
;
import
java.util.Enumeration
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.UUID
;
import
java.util.*
;
import
java.util.regex.Pattern
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONAware
;
import
com.alibaba.fastjson.JSONException
;
import
com.alibaba.fastjson.JSONStreamAware
;
import
com.alibaba.fastjson.*
;
import
com.alibaba.fastjson.parser.DefaultJSONParser
;
import
com.alibaba.fastjson.parser.Feature
;
import
com.alibaba.fastjson.parser.JSONLexer
;
...
...
@@ -184,6 +177,25 @@ public final class MiscCodec implements ObjectSerializer, ObjectDeserializer {
if
(
objVal
instanceof
String
)
{
strVal
=
(
String
)
objVal
;
}
else
{
if
(
objVal
instanceof
JSONObject
)
{
JSONObject
jsonObject
=
(
JSONObject
)
objVal
;
if
(
clazz
==
Currency
.
class
)
{
String
currency
=
jsonObject
.
getString
(
"currency"
);
if
(
currency
!=
null
)
{
return
(
T
)
Currency
.
getInstance
(
currency
);
}
String
symbol
=
jsonObject
.
getString
(
"currencyCode"
);
if
(
symbol
!=
null
)
{
return
(
T
)
Currency
.
getInstance
(
symbol
);
}
}
if
(
clazz
==
Map
.
Entry
.
class
)
{
return
(
T
)
jsonObject
.
entrySet
().
iterator
().
next
();
}
}
throw
new
JSONException
(
"except string value"
);
}
...
...
This diff is collapsed.
Click to expand it.
src/test/java/com/alibaba/json/bvt/CurrencyTest4.java
0 → 100644
+
37
-
0
View file @
9a07dc1e
package
com.alibaba.json.bvt
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
junit.framework.TestCase
;
import
java.util.Currency
;
public
class
CurrencyTest4
extends
TestCase
{
public
void
test_0
()
throws
Exception
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"currency"
,
"CNY"
);
String
text
=
JSON
.
toJSONString
(
jsonObject
);
Currency
currency
=
JSON
.
parseObject
(
text
,
Currency
.
class
);
assertSame
(
Currency
.
getInstance
(
"CNY"
),
currency
);
}
public
void
test_1
()
throws
Exception
{
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"currencyCode"
,
"CNY"
);
String
text
=
JSON
.
toJSONString
(
jsonObject
);
Currency
currency
=
JSON
.
parseObject
(
text
,
Currency
.
class
);
assertSame
(
Currency
.
getInstance
(
"CNY"
),
currency
);
}
public
static
class
VO
{
public
Currency
value
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help