Permalink
Browse files

bug fixed for MapPrettyFormat

  • Loading branch information...
1 parent 14689ff commit af96dfa3561810d0b3206b72be9154098c563d59 wenshao committed Jul 18, 2012
Showing with 25 additions and 0 deletions.
  1. +15 −0 pom.xml
  2. +10 −0 src/main/java/com/alibaba/fastjson/serializer/MapSerializer.java
View
15 pom.xml
@@ -186,6 +186,21 @@
<dependencies>
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>1.1.1</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>3.0.0.RELEASE</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
@@ -60,6 +60,8 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
serializer.setContext(parent, object, fieldName);
try {
out.write('{');
+
+ serializer.incrementIndent();
Class<?> preClazz = null;
ObjectSerializer preWriter = null;
@@ -118,6 +120,9 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
out.write(',');
}
+ if (out.isEnabled(SerializerFeature.PrettyFormat)) {
+ serializer.println();
+ }
out.writeFieldName(key, true);
} else {
if (!first) {
@@ -149,6 +154,11 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
} finally {
serializer.setContext(parent);
}
+
+ serializer.decrementIdent();
+ if (out.isEnabled(SerializerFeature.PrettyFormat) && map.size() > 0) {
+ serializer.println();
+ }
out.write('}');
}
}

0 comments on commit af96dfa

Please sign in to comment.