rm-datasource/src/test/java/io/seata/rm/datasource/undo/parser/FastjsonUndoLogParserTest.java
<reponame>tyc1210/seata-1/*
 *  Copyright 1999-2019 Seata.io Group.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package io.seata.rm.datasource.undo.parser;

import java.sql.Timestamp;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.ValueFilter;

import io.seata.common.loader.EnhancedServiceLoader;
import io.seata.rm.datasource.undo.BaseUndoLogParserTest;
import io.seata.rm.datasource.undo.UndoLogParser;

/**
 * @author Geng Zhang
 */
public class FastjsonUndoLogParserTest extends BaseUndoLogParserTest {

    FastjsonUndoLogParser parser = (FastjsonUndoLogParser) EnhancedServiceLoader.load(UndoLogParser.class, FastjsonUndoLogParser.NAME);

    @Override
    public UndoLogParser getParser() {
        return parser;
    }

    /**
     * disable super testTimestampEncodeAndDecode
     */
    @Override
    public void testTimestampEncodeAndDecode() {
        Timestamp encodeStamp = new Timestamp(System.currentTimeMillis());
        encodeStamp.setNanos(999999);
        SerializeConfig.getGlobalInstance().addFilter(Timestamp.class, new TimestampSerializer());
        byte[] encode = JSON.toJSONString(encodeStamp, SerializeConfig.getGlobalInstance()).getBytes();

    }

    private class TimestampSerializer implements ValueFilter {

        @Override
        public Object process(Object object, String name, Object value) {
            return null;
        }
    }
}