/src/main/java/com/alibaba/fastjson/serializer/BooleanArraySerializer.java
Java | 42 lines | 18 code | 6 blank | 18 comment | 4 complexity | 9041618cd03bf5cda0299b2127a15477 MD5 | raw file
1/*
2 * Copyright 1999-2101 Alibaba Group.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.alibaba.fastjson.serializer;
17
18import java.io.IOException;
19import java.lang.reflect.Type;
20
21/**
22 * @author wenshao<szujobs@hotmail.com>
23 */
24public class BooleanArraySerializer implements ObjectSerializer {
25
26 public static BooleanArraySerializer instance = new BooleanArraySerializer();
27
28 public final void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
29 SerializeWriter out = serializer.getWriter();
30
31 if (object == null) {
32 if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
33 out.write("[]");
34 } else {
35 out.writeNull();
36 }
37 return;
38 }
39
40 out.writeBooleanArray((boolean[]) object);
41 }
42}