2017-04-24 10 views
0

YAMLファイルをオブジェクトに変換して使用しようとしています。特殊文字で文字列を解析しようとすると、YAML Factoryは文字列を分割します。yaml jackson YAMLファクトリを使用した構文解析

出力がわかると、文字列が分割されていることがわかります。 お手伝いできますか?私たちはYAMLの機能を使用しようとしましたが、それでも成功することはできませんでした。

答えて

0

例:

We are trying to debug an issue. 

Following is my Object class: 



import com.fasterxml.jackson.annotation.JsonCreator; 
import com.fasterxml.jackson.annotation.JsonProperty; 

public class HelloWorld 
{ 

public String name; 
public String place; 
public String company; 

@JsonCreator 
public HelloWorld(@JsonProperty("name") String name, @JsonProperty("place") String place, @JsonProperty("company") String company) 
{ 
super(); 
this.name = name; 
this.place = place; 
this.company = company; 
} 

public String getName() 
{ 
return name; 
} 

public String getPlace() 
{ 
return place; 
} 

public String getCompany() 
{ 
return company; 
} 
} 

Main Class :+1: 

import com.fasterxml.jackson.annotation.JsonInclude.Include; 
import com.fasterxml.jackson.databind.ObjectMapper; 
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 

public class SampleHellp 
{ 

public static void main(String[] args) 
{ 

    String sample = "$(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) \"_\" + $(parent_RFSEVCService_evcID)"; 
    System.out.println(sample); 
    HelloWorld world = new HelloWorld("name", sample,"company"); 
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); 
    try 
    { 
    mapper.setSerializationInclusion(Include.NON_NULL); 
    // mapper.writeValue(new File("C:\\D\\Template.yaml"), template); 
    String writeValueAsString = mapper.writeValueAsString(world); 
    System.out.println(writeValueAsString); 
    // System.out.println(ReflectionToStringBuilder.toString(template, ToStringStyle.MULTI_LINE_STYLE)); 
    } 
    catch (Exception e) 
    { 
    throw new RuntimeException("Exception while converting Object to YAML ", e); 
    } 
} 
} 

Output : 

$(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) "_" + $(parent_RFSEVCService_evcID) 

name: "name" 
place: "$(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) "_" 
\ + $(parent_RFSEVCService_evcID)" 
company: "company" 
+0

をJackon-YAML-データバインディング:YAML発電機の次の機能を使用し

あなたは両方の答えを凝縮する必要があります。 2番目の情報から最初の情報を編集し、2番目の情報を削除します。 –

0

が解決:分割線

YAMLFactory yf = new YAMLFactory(); 
    yf.disable(YAMLGenerator.Feature.SPLIT_LINES); 
    ObjectMapper mapper = new ObjectMapper(yf); 

これは2.6の機能で利用可能であるOD

関連する問題