Commit 5de62055 authored by yihua.huang's avatar yihua.huang

use RawText as source for JsonPath #589

parent 211ac743
...@@ -19,6 +19,8 @@ import java.util.ArrayList; ...@@ -19,6 +19,8 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static us.codecraft.webmagic.model.annotation.ExtractBy.Source.RawText;
/** /**
* The main internal logic of page model extractor. * The main internal logic of page model extractor.
* *
...@@ -125,9 +127,12 @@ class PageModelExtractor { ...@@ -125,9 +127,12 @@ class PageModelExtractor {
ExtractBy extractBy = field.getAnnotation(ExtractBy.class); ExtractBy extractBy = field.getAnnotation(ExtractBy.class);
if (extractBy != null) { if (extractBy != null) {
Selector selector = ExtractorUtils.getSelector(extractBy); Selector selector = ExtractorUtils.getSelector(extractBy);
ExtractBy.Source source0 = extractBy.source();
if (extractBy.type()== ExtractBy.Type.JsonPath){
source0 = RawText;
}
FieldExtractor.Source source = null; FieldExtractor.Source source = null;
switch (extractBy.source()){ switch (source0){
case RawText: case RawText:
source = FieldExtractor.Source.RawText; source = FieldExtractor.Source.RawText;
break; break;
......
...@@ -77,7 +77,7 @@ public class PageModelExtractorTest { ...@@ -77,7 +77,7 @@ public class PageModelExtractorTest {
public static class ModelJsonStr { 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; private String name;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment