



import java.io.File;
import java.io.FileInputStream;
import com.google.protobuf.nano.MessageNano;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

import lombok.extern.slf4j.Slf4j;
import static nano.BaseResponse.Base_Response;

@Slf4j
public class BaseResponseTest {
    
    @SuppressWarnings("unchecked")
    public static <U extends MessageNano> void main(String args[]) {
        String path = "C:\\Users\\Administrator\\Desktop\\Emoney\\2422-different-span\\300684-2422-monthly-resp";
        
        try {
            FileInputStream in = new FileInputStream(new File(path));
            byte[] data=new byte[in.available()];
            in.read(data);
            in.close();
            
            Base_Response baseResponse = Base_Response.parseFrom(data);
            
            String className = baseResponse.detail.getTypeUrl().replace("type.googleapis.com/", "");
            className = "nano." + className.replace("_", "") + "$" + className;
            
            Class<U> clazz = (Class<U>)Class.forName(className);
            
            U nanoResponse = (U) MessageNano.mergeFrom((MessageNano)clazz.getDeclaredConstructor().newInstance(), baseResponse.detail.getValue());
            
            ObjectNode jo = new ObjectMapper().valueToTree(nanoResponse);
            log.info(jo.toPrettyString());
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
