mangstadt / ez-vcard

A vCard parser library for Java
Other
405 stars 93 forks source link

[Q] How do I get the `RawProperty`s? #126

Closed NightMachinery closed 2 years ago

NightMachinery commented 2 years ago

I have tried:

(filter
         (fn [p]
           (instance? p ezvcard.property.RawProperty))
         (seq (.getProperties c)))

But I get the following exception:

1. Caused by java.lang.ClassCastException
   class ezvcard.property.ProductId cannot be cast to class java.lang.Class
   (ezvcard.property.ProductId is in unnamed module of loader 'app';
   java.lang.Class is in module java.base of loader 'bootstrap')

                  core.clj:  146  clojure.core/instance?
                  core.clj:  146  clojure.core/instance?
                      REPL:  158  NightMachinery.vcard-to-json/eval12970/fn
                  core.clj: 2834  clojure.core/filter/fn
              LazySeq.java:   42  clojure.lang.LazySeq/sval
              LazySeq.java:   51  clojure.lang.LazySeq/seq
                   RT.java:  535  clojure.lang.RT/seq
                  core.clj:  139  clojure.core/seq
            core_print.clj:   53  clojure.core/print-sequential
            core_print.clj:  174  clojure.core/fn
            core_print.clj:  174  clojure.core/fn
              MultiFn.java:  234  clojure.lang.MultiFn/invoke
                pprint.clj:   40  cider.nrepl.pprint/pr/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  667  clojure.core/apply
                  core.clj: 1990  clojure.core/with-bindings*
                  core.clj: 1990  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
                pprint.clj:   37  cider.nrepl.pprint/pr
                pprint.clj:   29  cider.nrepl.pprint/pr
                  Var.java:  393  clojure.lang.Var/invoke
                 print.clj:  224  nrepl.middleware.print/wrap-print/fn/print
                 print.clj:  148  nrepl.middleware.print/send-nonstreamed/print-key/fn
                 print.clj:  147  nrepl.middleware.print/send-nonstreamed/print-key
                  core.clj: 2759  clojure.core/map/fn/fn
             protocols.clj:   49  clojure.core.protocols/iter-reduce
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   75  clojure.core.protocols/fn
             protocols.clj:   13  clojure.core.protocols/fn/G
                  core.clj: 6947  clojure.core/transduce
                  core.clj: 6933  clojure.core/transduce
                 print.clj:  156  nrepl.middleware.print/send-nonstreamed
                 print.clj:  138  nrepl.middleware.print/send-nonstreamed
                 print.clj:  174  nrepl.middleware.print/printing-transport/reify
                caught.clj:   58  nrepl.middleware.caught/caught-transport/reify
    interruptible_eval.clj:  123  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  442  clojure.main/repl/read-eval-print
                  main.clj:  458  clojure.main/repl/fn
                  main.clj:  458  clojure.main/repl
                  main.clj:  368  clojure.main/repl
               RestFn.java: 1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   84  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  152  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  218  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  217  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  832  java.lang.Thread/run

BTW, I wonder if you can add support for these properties:

item2.X-ABRELATEDNAMES;type=pref:Peter Smith
item2.X-ABLabel:_$!<Friend>!$_

This is the way Apple saves relations.

mangstadt commented 2 years ago

The VCard.getExtendedProperties() method returns all unrecognized properties. It returns a List<RawProperty> object.