use RawText as source for JsonPath #589

pull/202/merge
yihua.huang 8 years ago
parent 211ac74389
commit 5de6205563

@ -19,6 +19,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import static us.codecraft.webmagic.model.annotation.ExtractBy.Source.RawText;
/**
* The main internal logic of page model extractor.
*
@ -125,9 +127,12 @@ class PageModelExtractor {
ExtractBy extractBy = field.getAnnotation(ExtractBy.class);
if (extractBy != null) {
Selector selector = ExtractorUtils.getSelector(extractBy);
ExtractBy.Source source0 = extractBy.source();
if (extractBy.type()== ExtractBy.Type.JsonPath){
source0 = RawText;
}
FieldExtractor.Source source = null;
switch (extractBy.source()){
switch (source0){
case RawText:
source = FieldExtractor.Source.RawText;
break;

@ -77,7 +77,7 @@ public class PageModelExtractorTest {
public static class ModelJsonStr {
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name",source = ExtractBy.Source.RawText)
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name")
private String name;
}

Loading…
Cancel
Save