如果您对Failedtoconvertpropertyvalueoftype''java.lang.String''torequiredtype''java.ut...感兴趣,那么本文将是一篇不错的选
如果您对Failed to convert property value of type ''java.lang.String'' to required type ''java.ut...感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Failed to convert property value of type ''java.lang.String'' to required type ''java.ut...的详细内容,并且为您提供关于Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查、c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext、C++ Json Assertion failed type_ == nullValue || type_ == objectValue、C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...的有价值信息。
本文目录一览:- Failed to convert property value of type ''java.lang.String'' to required type ''java.ut...
- Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查
- c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext
- C++ Json Assertion failed type_ == nullValue || type_ == objectValue
- C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...
Failed to convert property value of type ''java.lang.String'' to required type ''java.ut...
实体类上加注解报错 Failed to convert property value of type ''java.lang.String'' to required type ''java.util.Date'' for property''startTime''; nested exception is org.springframework.core.convert.ConversionFailedException:
只要引入 jar 就可以了
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查
当使用 rabbitmq 作为 airflow 的 broker 的时候,启动 scheduler,即执行 airflow scheduler 命令的时候抛出以下异常:
Traceback (most recent call last):
File "/anaconda/anaconda3/bin/airflow", line 27, in <module>
args.func(args)
File "/anaconda/anaconda3/lib/python3.6/site-packages/airflow/bin/cli.py", line 818, in scheduler
......
......
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/connection.py", line 494, in _ensured
return fun(*args, **kwargs)
File "/anaconda/anaconda3/lib/python3.6/site-packages/kombu/messaging.py", line 203, in _publish
mandatory=mandatory, immediate=immediate,
File "/anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py", line 122, in basic_publish
mandatory or False, immediate or False,
TypeError: an integer is required (got type NoneType)
整体环境描述:
python3.6 + apache-airflow1.9.0 + rabbitmq 3.6
因为使用 redis 作为 broker 是可以正常运行的,但是换成 rabbitmq 之后就出现了这种情况。尝试过对 rabbitmq 降版本,对 airflow 降低版本,发现依然无解,说明并不是软件版本兼容问题。
于是进一步排查,单独使用 celery4.x 进行调试,发现 celery 可以正常运行,但是到了 airflow 下就出现问题,说明是配置问题。
但是 airflow 的官方文档中配置是相当简陋的,而源码中相关的配置又相当的多,实在无法定位。于是采用最粗暴的做法,调试,但是服务器无法远程,没有外网端口,不能远程调试,而且 airflow 并不支持 windows 平台。于是只能通过日志调试:
首先,根据异常提示,说明有配置属性为空导致了这个异常,于是在异常处加上打印日志:
$ vi /anaconda/anaconda3/lib/python3.6/site-packages/librabbitmq/__init__.py
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
print("---------------------------------------")
print(self.channel_id)
print("---------------------------------------")
print(body)
print("---------------------------------------")
print(exchange)
print("---------------------------------------")
print(routing_key)
print("---------------------------------------")
print(properties)
print("---------------------------------------")
print(mandatory)
print("---------------------------------------")
print(immediate)
print("---------------------------------------")
#if properties["priority"] is None: 加上这一句后就不会抛出异常了
# properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
打印结果如下:
---------------------------------------
1
---------------------------------------
b''\x80\x02}q\x00(X\x04\x00\x00\x00taskq\x01X1\x00\x00\x00airflow.executors.celery_executor.execute_commandq\x02X\x02\x00\x00\x00idq\x03X$\x00\x00\x0077410b3a-75c6-4ba0-a448-7048c029e80cq\x04X\x04\x00\x00\x00argsq\x05]q\x06X\xcc\x00\x00\x00airflow run example_passing_params_via_test_command run_this 2018-07-02T01:04:00 --local -sd /anaconda/anaconda3/lib/python3.6/site-packages/airflow/example_dags/example_passing_params_via_test_command.pyq\x07aX\x06\x00\x00\x00kwargsq\x08}q\tX\x07\x00\x00\x00retriesq\nK\x00X\x03\x00\x00\x00etaq\x0bNX\x07\x00\x00\x00expiresq\x0cNX\x03\x00\x00\x00utcq\r\x88X\t\x00\x00\x00callbacksq\x0eNX\x08\x00\x00\x00errbacksq\x0fNX\t\x00\x00\x00timelimitq\x10NN\x86q\x11X\x07\x00\x00\x00tasksetq\x12NX\x05\x00\x00\x00chordq\x13Nu.''
---------------------------------------
default
---------------------------------------
celery
---------------------------------------
{''reply_to'': ''d0552f0c-b341-30b6-9edb-fa9599715d6c'', ''correlation_id'': ''77410b3a-75c6-4ba0-a448-7048c029e80c'', ''delivery_mode'': 2, ''content_type'': ''application/x-python-serialize'', ''content_encoding'': ''binary'', ''headers'': {}, ''priority'': None}
---------------------------------------
None
---------------------------------------
None
---------------------------------------
因为 mandatory 和 immediate 是 bool 类型,且都尝试过给其设置值,但是依然报错,最后还为 None 的就剩下 priority 属性为 None 了。于是尝试在代码中对其设置一个 int 类型的值,结果再次运行并无异常,说明缺少优先级属性导致了这个问题,于是可以在 priority 属性为 None 的时候给它一个默认值:
......
......
if isinstance(body, tuple):
body, properties = body
elif isinstance(body, self.Message):
body, properties = body.body, body.properties
if properties["priority"] is None: #加上这一句后就不会抛出异常了
properties["priority"] = 0
return self.connection._basic_publish(
self.channel_id, body, exchange, routing_key, properties,
mandatory or False, immediate or False,
)
......
......
后续发现这样修改源码确实不会出现之前的问题,但是会出现
TypeError can''t pickle memoryview objects
之类的异常,后确认是 librabbitmq 2.0.0 + celery 4.x 的兼容性问题,于是选择使用 pyamqp 协议而不是使用默认的 amqp 协议,具体操作就是将 broker_url 改为如下格式:
broker_url = pyamqp://cord:123456@10.55.63.51:5672//
### transport://userid:password@hostname:port/virtual_host
而将 celery_result_backend 改为其他实现,比如 mysql:
celery_result_backend = db+mysql://af:123456@10.55.63.51/airflow
至此问题解决。
总结:
在排查问题的时候需要针对问题深入排查,而不是无根据的臆测,要针对提示去逐步排查,而不是一味无目的去尝试。
虽然该问题已解决,但是推测应该是缺失相关配置导致了这个问题,但是我加上了优先级相关的配置并不起作用,所以暂时通过修改源码修复这个问题。
c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext
除了在之前和之后切换文化之外,有没有一种聪明的方法来获取ITypeDescriptorContext或使用InvariantCulture调用此方法的其他选项?
解决方法
TypeConverter.ConvertToString(null,CultureInfo.InvariantCulture,Object);
C++ Json Assertion failed type_ == nullValue || type_ == objectValue
遇到一个 json 的问题,Assertion failed type_ == nullValue || type_ == objectValue用 C++ 谢了一个通过调用 jni 访问 java 类的方法,穿入的参数是 string 数组,但是由于 java 的原因,所以实际穿入的是 jobjectarray
jobjectArray str_arr_1 = CstringtoObject(env,arg_of_1); jobjectArray str_arr_2 = CstringtoObject(env,arg_of_2); jstring ss = (jstring)env->CallObjectMethod(ec,mid,str_arr_1 ,str_arr_2 ); string re = JStringToCString(env,res);
其中 CstringtoObject 是吧字符串数组转化为对象数组,然后返回一个 jstring 格式的 Json 字符串,然后把 jstring 格式的字符串转化为 string 格式的 re;
之后就是把 json 转成结构体了。
{"total:4000","JsonList":
["{"SHIPENAME":"HELLO","SHIPETYPE":"TUG"}",
"{"SHIPENAME":"WORD,"SHIPETYPE":"PASSANGER"}"
]
}
vector<struct info> stringtovector(string ss) { Json::Features feature = Json::Features::strictMode(); Json::Value val; Json::Reader reader(feature); vector<struct ship_info> vt; if(reader.parse(ss,val)) { Json::Value val_arry = val["JsonList"]; int isize = val_arry.size(); for(int nindex = 0;nindex<isize;++nindex) { ship_info ship; ship.SHIPENAME = val_arry[nindex]["SHIPENAME"].asString(); ...... } } return vt }
在
ship.SHIPENAME = val_arry[nindex]["SHIPENAME"].asString();
这一句会返回 C++ Json Assertion failed type_ == nullValue || type_ == objectValue 错误,不知道为什么,虽然我解析的是 [{}{}] 形式的 json 但是我也用了 val [index]["name"].c_str (); 了呀??
求对 JSON 比较熟的人来指点一下。
C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...
先看代码(不想看代码可以直接看代码后的问题描述)
//header.h
#ifndef _HEADER_H
#define _HEADER_H
#define defaultSize 128
#include<iostream>
#include<string.h>
using namespace std;
class myString
{
private:
char *ch;
int curLength;
int maxSize;
public:
myString(int sz=defaultSize);
myString(const char *init);
myString(const myString& ob);
~myString(){delete []ch;}
void print();
int Length()const;
myString operator()(int pos, int len);
myString& operator = (myString& ob);
};
myString& myString::operator = (myString& ob)
{
if(&ob!=this)
{
delete[]ch;
this->ch = new char[ob.maxSize];
this->maxSize = ob.curLength;
strcpy(this->ch, ob.ch);
this->curLength = ob.curLength;
}
else
{
cerr<<"String copy error\n";
}
return *this;
}
myString myString::operator()(int pos, int len)
{
myString temp;
if(pos<0 || len<=0 || pos+len-1>=this->maxSize)
{
temp.curLength = 0;
temp.ch[0] = ''\0'';
}
else
{
if(pos+len-1 >= this->curLength)
len = this->curLength-pos;
temp.curLength = len;
for(int i=0,j=pos; i<len; ++i,++j)
temp.ch[i] = this->ch[j];
temp.ch[len] = ''\0'';
}
return temp;
}
int myString::Length()const
{
return this->curLength;
}
void myString::print()
{
cout<<this->ch<<endl;
}
myString::myString(int sz)
{
this->maxSize = sz;
this->ch = new char[this->maxSize+1];
if(this->ch == NULL)
{
cerr<<"Allocation ERROR\n";
exit(1);
}
this->curLength = 0;
ch[0] = ''\0'';
}
myString::myString(const char *init)
{
int len = strlen(init);
this->maxSize = (len > defaultSize) ? len : defaultSize;
this->ch = new char[this->maxSize+1];
if(this->ch == NULL)
{
cerr<<"Application Memory ERROR\n";
exit(1);
}
this->curLength = len;
strcpy(this->ch, init);
}
myString::myString(const myString& ob)
{
this->maxSize = ob.maxSize;
this->ch = new char[this->maxSize+1];
if(this->ch == NULL)
{
cerr<<"Application Memory ERROR\n";
exit(1);
}
this->curLength = ob.curLength;
strcpy(this->ch, ob.ch);
}
#endif
//main.cpp
#include"header.h"
int main()
{
myString st(10), st1("ABCDEFG");
myString st2(st1);
st.print(), st1.print(), st2.print();
st = st1(0, 4);//???
st.print();
return 0;
}
这是一个字符串类,问题出现在了两个符号重载,()和=
()重载是想对字符串对象做一个切片,返回一个临时对象,=重载就不用说了,就是赋值。
问题就出现在总是无法将这个切片后的临时对象赋值给等号前的对象,编译后如下:
在网上一番查找后找到一个类似问题
https://blog.csdn.net/u011068702/article/details/64443949
也就是说,在st1(0,4)时存在了一个临时变量,当把这个临时变量传给st时,由于在=重载函数声明中,参数为myString&,而并不是常量引用。
这个错误是C++编译器的一个关于语义的限制。
如果一个参数是以非const引用传入,c++编译器就有理由认为程序员会在函数中修改这个值,并且这个被修改的引用在函数返回后要发挥作用。但如果你把一个临时变量当作非const引用参数传进来,由于临时变量的特殊性,程序员并不能操作临时变量,而且临时变量随时可能被释放掉,所以,一般说来,修改一个临时变量是毫无意义的,据此,c++编译器加入了临时变量不能作为非const引用的这个语义限制。
了解这个语义以后就简单了,只需给=重载参数加上const常量限制符。
(类中=重载函数声明也别忘了要加上const)
加上以后程序的运行结果
可以,很正确。
总结:
c++中临时变量不能作为非const的引用参数
2019/12/14更新
最近看到一个类似问题,即C++11
int i=0;
++++i;//这样是可以的
i++++;//这样就是错误的
我们知道前++就是直接对对象自增后返回对象,而后++会先返回记录当前值,在自增,最后返回一个无名的临时对象,那么 i++++就是让第一个后++返回的无名临时对象再自增,这样对C++是无意义的,所以这样就无法编译通过。//ps.这就是常说的 举一隅以三隅反 吧
关于Failed to convert property value of type ''java.lang.String'' to required type ''java.ut...的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Airflow:TypeError an integer is required (got type NoneType) 一次诡异问题排查、c# – 如何使用InvariantCulture调用TypeConverter.ConvertTo或ConvertToString但不实现ITypeDescriptorContext、C++ Json Assertion failed type_ == nullValue || type_ == objectValue、C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘m...等相关内容,可以在本站寻找。
本文标签: