나는 MyClass
클래스를 가지고 있습니다. 사용자 지정 변환기를 구현하지 않고 serialize하면 사람이 읽을 수 없습니다.중간 객체로 변환하여 쓰고 읽는 XStream 변환기를 작성하는 방법은 무엇입니까?
MyClass
과 MyClassDTO
사이에서 변환을 구현했습니다.
MyClassDTO
은 XStream 표준 직렬화를 사용할 때 사람이 읽을 수 있습니다.
XStream Converter 직렬화 및 비 직렬화 MyClass
을 작성하고 싶습니다.
Converter.marshal
에 대한 구현은 다음과 같아야합니다. MyClass
개체를 MyClassDTO
으로 변환하고 MyClassDTO
의 기본 직렬화를 호출합니다.
Converter.unmarshal
의 경우 : MyClassDTO
개체의 기본값을 비 직렬화하여 MyClass
으로 변환하십시오.
간단한 동작으로 이러한 동작을 구현하는 방법은 무엇입니까?
내가 XStream Converter Tutorial을 통해 보았지만 필요한 것을 찾지 못했습니다.
나는 아래의 스텁을 작성해야합니다 :
class MatrixConverter<T> : Converter
where T : new()
{
public bool CanConvert(Type type)
{
return type == typeof(Matrix<T>);
}
public void ToXml(object value, Type expectedType, XStreamWriter writer, MarshallingContext context)
{
Matrix<T> matrix = value as Matrix<T>;
if (matrix == null)
{
throw new ArgumentException();
}
// the code which I am asked about should follow here
}
public object FromXml(Type expectedType, XStreamReader reader, UnmarshallingContext context)
{
Matrix<T> matrix = null;
// the code which I am asked about should follow here
}
}
당신의 절차와 전술을 게시 할 수 있습니다 ... –
어떤 절차와 전술? – sergtk
나는 당신이 노력하고있는 코드 샘플을 게시해야한다는 것을 의미했다 ... –