public MessagePropertyValue()

in src/main/java/com/aliyun/mns/model/MessagePropertyValue.java [18:53]


    public MessagePropertyValue(PropertyType type, String value) {
        if (type == null || value == null) {
            throw new IllegalArgumentException("type and value can not be null");
        }
        this.dataType = type;
        switch (type) {
            case NUMBER:
                try {
                    // 校验是否是数字
                    Double.parseDouble(value);
                    this.stringValue = value;
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("Invalid number format: " + value);
                }
                break;
            case STRING:
                this.stringValue = value;
                break;
            case BOOLEAN:
                // 校验是否为合法的布尔值
                if (!"true".equalsIgnoreCase(value) && !"false".equalsIgnoreCase(value)) {
                    throw new IllegalArgumentException("Invalid boolean value: " + value);
                }
                this.stringValue = value;
                break;
            case BINARY:
                try {
                    this.binaryValue = value.getBytes(DEFAULT_CHARSET);
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException("Not support encoding: " + DEFAULT_CHARSET);
                }
                break;
            default:
                throw new IllegalArgumentException("Invalid property type: " + type);
        }
    }