package com.leromro.core.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

public class JsonParser {
    public static List<double[]> parseCoordinates(String json) throws Exception {
        ObjectMapper mapper = new ObjectMapper();
        // 先解析为List<List<Double>>，再转换为List<double[]>
        List<List<Double>> tempList = mapper.readValue(json,new TypeReference<List<List<Double>>>() {});
        List<double[]> result = new ArrayList<>();
        for (List<Double> subList : tempList) {
            double[] arr = new double[subList.size()];
            for (int i = 0; i < subList.size(); i++) {
                arr[i] = subList.get(i); // 自动拆箱为double
            }
            result.add(arr);
        }
        return result;
    }
}